-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBUGCAL.cpp
More file actions
49 lines (48 loc) · 868 Bytes
/
BUGCAL.cpp
File metadata and controls
49 lines (48 loc) · 868 Bytes
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
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;string a,b;
for(cin>>t;t--;)
{
cin>>a>>b;
int la=a.length()-1;int lb=b.length()-1;
if(la==lb and la==0)
cout<<((int)a[la]+(int)b[lb]-96)%10<<endl;
else
{
if(la>=lb)
{
while(lb>=0)
a[la]=((int)a[la--]+(int)b[lb--]-96)%10+48;
int i=0;
while(a[i]=='0')
++i;
if(i==a.length())
cout<<0;
else
for(;i<a.length();++i)
cout<<a[i];
cout<<endl;
}
else if(la<lb)
{
while(la>=0)
b[lb]=((int)a[la--]+(int)b[lb--]-96)%10+48;
int i=0;
while(b[i]=='0')
++i;
if(i==b.length())
cout<<0;
else
for(;i<b.length();++i)
cout<<b[i];
cout<<endl;
}
}
}
return 0;
}