-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3116.cpp
56 lines (45 loc) · 846 Bytes
/
3116.cpp
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
/*
*3116 ¸ß¾«¶ÈÁ·Ï°Ö®¼õ·¨
*/
#include <iostream>
#include <string>
using namespace std;
string ABAdd(string a, string b)
{
string::reverse_iterator arbegin, arend, brbegin, brend;
arbegin = a.rbegin();
arend = a.rend();
brbegin = b.rbegin();
brend = b.rend();
int cadd = 0,temp;
string c = "";
while(arbegin!=arend && brbegin!=brend)
{
temp = *arbegin++ - '0' + *brbegin++ -'0' + cadd;
c.push_back(temp%10+'0');
cadd = temp/10;
}
while(arbegin!=arend)
{
temp = *arbegin++ -'0'+ cadd;
c.push_back(temp%10+'0');
cadd = temp/10;
}
while(brbegin!=brend)
{
temp = *brbegin++ - '0'+ cadd;
c.push_back(temp%10+'0');
cadd = temp/10;
}
if(cadd)
c.push_back(cadd+'0');
return string(c.rbegin(),c.rend());
}
int main()
{
string a, b, c;
cin >> a >> b;
c = ABAdd(a,b);
cout << c << endl;
return 0;
}