Title Link: http://www.patest.cn/contests/pat-a-practise/1065
Surface:
1065. A+b and C (64bit) time limit
Memory Limit 65536 KB
Code length limit 16000 B
Program Standard author HOU, qiming
Given three integers A, B and C in [ -263, 263], you is supposed to tell whether A+b > C.
Input Specification:
The first line of the input gives the positive number of test cases, T (<=10). Then T-test cases follow, each consists of a single line containing three integers a, B and C, separated by single spaces.
Output Specification:
For each test case, output in one line "case #X: True if a+b>c, or" case #X: false "Otherwise, where X is the case num ber (starting from 1). Sample Input:
3
1 2 3
2 3 4
9223372036854775807-9223372036854775808 0
Sample Output:
Case #1: False Case
#2: True Case
#3: false
Main topic:
Determine if A+B is greater than C.
Solving:
Because the direct calculation will explode long long, first reduce and then add also not, then take the 10 part of the calculation, modulo 10 is calculated separately. Finally, the results can be collated.
Code:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
#define LL Long Long
int main ()
{
int n;
LL a,ab1,ab2,b,c,c1,c2,t1,t2;
cin>>n;
for (int i=1;i<=n;i++)
{
cout<< ' case # ' <<i<< ': ';
cin>>a>>b>>c;
AB1=A/10+B/10;
ab2=a%10+b%10;
C1=C/10;
c2=c%10;
T1=AB1-C1;
T2=AB2-C2;
t1+= (T2/10);
t2%=10;
if (t2<0)
t2+=10,t1-=1;
if (t1<0| | (t1==0&&t2==0)) cout<< "false\n";
else cout<< "true\n";
}
return 0;