题目描述
给定区间[-2的31次方, 2的31次方]内的3个整数A、B和C,请判断A+B是否大于C。
输入描述:
输入第1行给出正整数T(<=10),是测试用例的个数。随后给出T组测试用例,每组占一行,顺序给出A、B和C。整数间以空格分隔。
输出描述:
对每组测试用例,在一行中输出“Case #X: true”如果A+B>C,否则输出“Case #X: false”,其中X是测试用例的编号(从1开始)。
输入例子:
4
1 2 3
2 3 4
2147483647 0 2147483646
0 -2147483648 -2147483647
输出例子:
Case #1: false
Case #2: true
Case #3: true
Case #4: false
//起初自己写的思路如下。
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int T;
int A,B,C;
cin>>T;
int i=1;
while(i<=T){
cin>>A >>B >>C;
if((A+B)>C){
cout<<"Case #"<<i<<": true"<<endl;
}else{
cout<<"Case #"<<i<<": false"<<endl;
}
++i;
}
return 0;
}
测试节点结果是。
测试点
测试点 结果 用时(ms) 内存(KB)
1 答案正确 4 376
2 答案错误 4 380
3 答案错误 4 380
4 答案正确 4 504
5 答案正确 5 508
6 答案正确 4 504
7 答案正确 5 340
未通过的地方:
测试用例:
1
-2147483648 -2147483648 -2147483648
对应输出应该为:
Case #1: false
你的输出为:
Case #1: true
int 自然没有那么长。
只需要将代码中的 int A,B,C; 改为:
long long A,B,C;