-
Notifications
You must be signed in to change notification settings - Fork 0
/
1065 A+B and C (64bit).cpp
98 lines (98 loc) · 2.52 KB
/
1065 A+B and C (64bit).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
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
89
90
91
92
93
94
95
96
97
98
/*
//简单方法
#include <iostream>
using namespace std;
int main(){
long long a, b, c;
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%lld%lld%lld", &a, &b, &c);
if(a > 0 && b > 0 && a + b < 0)
printf("Case #%d: true\n", i + 1);
else if(a < 0 && b < 0 && a + b >= 0)
printf("Case #%d: false\n", i + 1);
else if(a + b > c)
printf("Case #%d: true\n", i + 1);
else
printf("Case #%d: false\n", i + 1);
}
return 0;
}
*/
/**
* 虽然知道就题论题会有很多简洁的解法,还是头铁花了点时间写了个string加法出来,bug主要来自于注释那个地方。
* */
#include <iostream>
#include <algorithm>
using namespace std;
string plu(string a, string b){
if(a.length() > b.length()){
string tmp = a;
a = b;
b = tmp;
}
string ans = "";
int c = 0;
for(int i = 1; i <= b.length(); i++){
int aa, bb;
if(a.length() >= i){ // 比如a.length()的值是2, a.length() >= i正常工作,而a.length() - i >= 0则一直显示为正。难道c这么弱智的吗?
aa = a[a.length() - i] - '0';
}
else
aa = 0;
bb = b[b.length() - i] - '0';
int tmp = aa + bb + c;
c = tmp / 10;
ans += (char)(tmp % 10 + '0');
}
if(c == 1)
ans += '1';
reverse(ans.begin(), ans.end());
return ans;
}
bool cmp(string a, string b){
int i = 0, j = 0;
while(a[i] == '0')i++;
while(b[j] == '0')j++;
if(a.length() - i != b.length() - j)
return a.length() - i > b.length() - j;
for(int k = 0; k < a.length() - i; k++){
if(a[i + k] != b[j + k])
return a[i + k] > b[j + k];
}
return false;
}
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
string a, b, c, left = "0", right = "0";
cin >> a >> b >> c;
if(a[0] == '-'){
a = a.substr(1);
right = plu(right, a);
}
else{
left = plu(left, a);
}
if(b[0] == '-'){
b = b.substr(1);
right = plu(right, b);
}
else{
left = plu(left, b);
}
if(c[0] == '-'){
c = c.substr(1);
left = plu(left, c);
}
else{
right = plu(right, c);
}
if(cmp(left, right))
printf("Case #%d: true\n", i);
else
printf("Case #%d: false\n", i);
}
}