1065. A+B and C (64bit) (20)

100 ms

65536 kB

16000 B

Standard

HOU, Qiming

Given three integers A, B and C in [-263, 263], you are 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 number (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

判断A+B是否大于C。

因为直接计算会爆long long，先减再加也不行，那么就取除10部分计算，模10部分分别计算。最后把结果整理一下判断即可。

#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;
} 

PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】

2015-08-20 10:09:44

浙大PAT 1065. A+B and C (64bit) (20)

2014-03-07 11:39:03

PAT Advanced Level 1002. A+B for Polynomials (25)(Java)

2014-09-13 23:03:23

PAT-PAT (Advanced Level) Practise 1100 Mars Numbers (20)【二星级】

2015-09-19 09:40:36

PAT-PAT (Advanced Level) Practise The Dominant Color (20) (map计数)【二星级】

2015-11-19 22:42:39

PAT (Advanced Level) Practise 1065 A+B and C (64bit) (20)

2016-03-18 16:45:06

1065. A+B and C (64bit) (20)【逻辑】——PAT (Advanced Level) Practise

2015-12-18 22:43:14

PAT-PAT (Advanced Level) Practise 1012 The Best Rank (25) （简单模拟）【二星级】

2015-11-04 22:21:44

A+B and C (64bit) (20)

2017-03-16 21:24:50

1065. A+B and C (64bit) (20)-PAT甲级

2017-04-14 02:25:11