-
Notifications
You must be signed in to change notification settings - Fork 0
/
0015.cc
80 lines (73 loc) · 1.52 KB
/
0015.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <sstream>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cassert>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
const int max = 80;
const int zero = 48;
string c1 = "";
string c2 = "";
int p = 0;
std::cin >> p;
for(int k=0;k<p;++k){
std::cin >> c1;
std::cin >> c2;
string ans = "";
int cl = 0;
for(int j= 1;(j<=c1.size())||(j<=c2.size());++j){
if(j<=c1.size()&&j>c2.size()){
if(c1.at(c1.size()-j)+cl>zero+9){
ans.insert(0,1,c1.at(c1.size()-j)+cl-10);
cl = 1;
}else{
ans.insert(0,1,c1.at(c1.size()-j)+cl);
cl = 0;
}
}else if(j<=c2.size()&&j>c1.size()){
if(c2.at(c2.size()-j)+cl>zero+9){
ans.insert(0,1,c2.at(c2.size()-j)+cl-10);
cl = 1;
}else{
ans.insert(0,1,c2.at(c2.size()-j)+cl);
cl = 0;
}
}else{
if(c2.at(c2.size()-j)+c1.at(c1.size()-j)-zero+cl > zero+9){
ans.insert(0,1,c2.at(c2.size()-j)+c1.at(c1.size()-j)-zero+cl - 10);
cl = 1;
}else{
ans.insert(0,1,c2.at(c2.size()-j)+c1.at(c1.size()-j)-zero+cl);
cl = 0;
}
}
}
if(cl ==1){
ans.insert(0,1,'1');
}
if(ans.size()>max){
std::cout << "overflow" << std::endl;
}else{
std::cout << ans << std::endl;
}
}
return 0;
}