-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathCompare two Large Numbers
62 lines (47 loc) · 1015 Bytes
/
Compare two Large Numbers
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
#include <bits/stdc++.h>
using namespace std;
int main() {
int t; cin>>t;
while(t--)
{
string s1,s2; cin>>s1>>s2;
int i=0;
while(s1[i]=='0')
{
s1.erase(i,1);
if(s1=="")
break;
}
while(s2[i]=='0')
{s2.erase(i,1);
if(s2=="")
break;
}
int n1=s1.length(),n2=s2.length();
if(n1>n2)
cout<<2<<endl;
else if(n2>n1)
cout<<1<<endl;
else
{ int i=0;
for( i=0;i<n1;i++)
{
if(s1[i]>s2[i])
{
cout<<2<<endl;
break;
}
else if(s1[i]<s2[i])
{
cout<<1<<endl;
break;
}
else
continue;
}
if(i==n1)
cout<<3<<endl;
}
}
return 0;
}