[题目链接]https://pintia.cn/problem-sets/994805342720868352/problems/994805406352654336
正常的写法是用long long 定义数据,判断溢出,参考代码:
#include <cstdio>
int main(){
int t;
scanf("%d",&t);
for (int i=0; i<t; i++){
long long a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
long long temp=a+b;
if (a>0 && b>0 && temp<0){
printf("Case #%d: true\n",i+1);//正溢
}else if (a<0 && b<0 && temp>=0){
printf("Case #%d: false\n",i+1);//负溢
}else if (temp>c){
printf("Case #%d: true\n",i+1);//无溢出
}else {
printf("Case #%d: false\n",i+1);
}
}
不正常的写法,投机取巧:
#include <cstdio>
int main(){
int t;
scanf("%d",&t);
for (int i=0; i<t; i++){
long double a,b,c; //用double不行,用long double可以
scanf("%llf%llf%llf",&a,&b,&c);
if (a+b>c) printf("Case #%d: true\n",i+1);
else printf("Case #%d: false\n",i+1);
}
}