-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPP0321.cpp
52 lines (42 loc) · 1004 Bytes
/
CPP0321.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
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define chk cout << "<< * checked * >>" << endl;
#define db cout << '<' << "i" << '=' << i << '>' << endl
using namespace std;
void getMinus(string a, string b){
if(a == b){
cout << 0 << endl; return;
}
while(a.length() < b.length()) a = '0' + a;
while(a.length() > b.length()) b = '0' + b;
if(a < b) swap(a, b);
// cout << a << ' ' << b << endl;
string ans = "";
long long mark = 0;
for(int i=a.length()-1; i>=0; i--){
int tmp = a[i] - b[i] + mark;
mark = 0;
if(tmp < 0){
tmp+=10; mark=-1;
}
tmp += '0';
ans += tmp;
}
for(int i=ans.length()-1; i>=0; i--) cout << ans[i];
cout << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
cin.ignore();
while(t--){
string a, b;
cin >> a >> b;
getMinus(a, b);
}
return 0;
}