摘要
今天闲着没事开始准备一下pat,以下是自己的一些错误和总结。
第一次提交:
#include <cstdio>
int main(){
int n,A,B,C;
int X=1;
scanf("%d",& n);
while(n!=0){
scanf("%d",&A);
scanf("%d",&B);
scanf("%d",&C);
if(A+B>C){
printf("Case #%d: true\n",X);
}
else{
printf("Case #%d: false\n",X);
}
n = n-1;
X=X+1;
}
return 0;
}
第一次提交9分,注意题目给的范围。int型的数据范围为-2的31方到2的31次方-1,所以必须使用long long型。
修改后:
#include <cstdio>
int main(){
long long n,A,B,C;
int X=1;
scanf("%d",& n);
while(n!=0){
scanf("%lld",&A);
scanf("%lld",&B);
scanf("%lld",&C);
if(A+B>C){
printf("Case #%d: true\n",X);
}
else{
printf("Case #%d: false\n",X);
}
n = n-1;
X=X+1;
}
return 0;
}
标准答案:
#include <cstdio>
int main(){
int T, tcase =1;//输入第 1 行给出正整数 T (≤10),是测试用例的个数。
scanf("%d",& T);
while(T--){ //此语句表示while循环T次
long long a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
/*以上语句等于
scanf("%lld",&a);
scanf("%lld",&b);
scanf("%lld",&c);
*/
if(a+b>c){
printf("Case #%d: true\n", tcase++);
}else{
printf("Case #%d: false\n", tcase++);//同上文中输出完毕后x=x+1
}
}
return 0;
}
注意事项
- 输入法切换导致的全角半角,中文符号英文符号等。
- 对于输出结果的要求直接从题目中复制,防止格式出现不同,如本题中Case ,C要大写,Case后面有空格,多多留心。
- 注意return 0;
- 牢记
#include <cstdio>
int main(){
}