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
模拟题:
1.看到大数,脑子里第一想法都是模拟, 加法,减法,比较函数,正负数。 没有分析,题目的数据范围,我们可以怎样是最容易写的。
2. 数据范围自己脑子里一片懵逼, 这个范围对应的类型也不清楚,或者说没有概念,之前没有重视【觉得粗略看一下就ok,完全错误的想法,我们要将只是全都装进脑子里,博客只是整理思路,为了更好理解】
3.大数为什么用模拟,不知道,反正大数都是用模拟。自己之前的想法,大数计算是因为溢出,我们采用模拟,在溢出的情况下。这道题,不是所有的情况都是溢出的,自己完全把题想难了,没有看到这道题的数据范围,可能的情况分类。
溢出只会发生在 两种情况下, 两边都是正数,或者两边都是负数,所以我们完全可以只用 大整数加法来考虑。写的复杂了,一定要思考怎么写,有用么,是不是可以不写。
当然 不能作为 输入,因为超过了 的最大值,题目要求了,但是评测数据没有
样例 , ,
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
#define rep(i,a,b) for(int i=a;i<b;++i)
const int N=1010;
int S1[N],S2[N],S[N];
void show(int* S,int p){
rep(i,0,p)printf("%d",S[i]);
printf("\n");
}
int Add(ULL A,ULL B){
int p1=0,p2=0;
while(A){
S1[p1++]=A%10;
A/=10;
}
while(B){
S2[p2++]=B%10;
B/=10;
}
int p=0,sum=0;
while(p<min(p1,p2)){
int x=(sum+S1[p]+S2[p]);
S[p++]=x%10;
sum=x/10;
}
while(p<p1){
int x=sum+S1[p];
S[p++]=x%10;
sum=x/10;
}
while(p<p2){
int x=sum+S2[p];
S[p++]=x%10;
sum=x/10;
}
if(sum)S[p++]=sum;
/*
printf("***\n");
show(S,p);
show(S1,p1);
show(S2,p2);
*/
return p;
}
int Comp(int n,ULL C){
int p=0;
while(C){
S1[p++]=C%10;
C/=10;
}
show(S1,p);
show(S,n);
if(n>p)return 1;
if(n<p)return -1;
for(int i=n-1;i>=0;i--){
if(S[i]<S1[i])return -1;
if(S[i]>S1[i])return 1;
}
return 0;
}
/*
100
9223372036854775807 1 9223372036854775806
*/
int main(){
LL A,B,C;
int T;
scanf("%d",&T);
rep(kase,0,T){
scanf("%lld %lld %lld",&A,&B,&C);
int ok=0;
if(A>0&&B>0){
if(C>0){
unsigned long long a=A,b=B,c=C;
int p=Add(a,b);
int x=Comp(p,c);
if(x>0)ok=1;
}else{
ok=1;
}
}else if(A<0&&B<0){
if(C<0){
unsigned long long a=-A,b=-B,c=-C;
int p=Add(a,b);
int x=Comp(p,c);
if(x<0)ok=1;
}
}else{
if(A+B>C)ok=1;
}
if(ok){
printf("Case #%d: true\n",kase+1);
}else{
printf("Case #%d: false\n",kase+1);
}
}
return 0;
}