-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGEOPROB.c
89 lines (83 loc) · 1.23 KB
/
GEOPROB.c
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
79
80
81
82
83
84
85
86
87
88
#include<bits/stdc++.h>
using namespace std;
string sum(string a, string b)
{
char z = '0';
while(a.size() > b.size())
{
b = '0' + b;
}
while(b.size() > a.size())
{
a = '0' + a;
}
int carry = 0;
int tmp;
int i;
string ans = "";
for(i=a.size()-1;i>=0;--i)
{
tmp = (a[i] - '0') + (b[i] - '0') + carry;
carry = 0;
z = tmp%10 + '0';
carry = tmp/10;
ans = z + ans;
}
while(carry > 0)
{
z = carry%10 + '0';
ans = z + ans;
carry/=10;
}
return ans;
}
string sub(string a, string b)
{
while(a.size() > b.size())
{
b = '0' + b;
}
while(b.size() > a.size())
{
a = '0' + a;
}
string ans = "";
char z;
int tmp;
int i;
for(i=0;i<b.size();++i)
{
tmp = b[i] - '0';
tmp=9-tmp;
z = tmp + '0';
b[i] = z;
}
ans = sum(a,b);
ans = ans.substr(1);
string st = "1";
ans = sum(ans,st);
z = '0';
while(*ans.begin() == z)
{
ans = ans.substr(1);
}
return ans;
}
int main()
{
string c,b,d;
//cout<<sum(a,b)<<endl;
string a,tmp,tmp2;
int t;
cin>>t;
while(t--)
{
cin>>b>>c>>d;
tmp = sum(c,c);
tmp2 = sum(b,d);
a = sub(tmp,tmp2);
cout<<a<<endl;
}
//cin>>b>>c;
//cout<<sub(b,c)<<endl;
}