PAT_B1011

摘要
今天闲着没事开始准备一下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;
}

注意事项

  1. 输入法切换导致的全角半角,中文符号英文符号等。
  2. 对于输出结果的要求直接从题目中复制,防止格式出现不同,如本题中Case ,C要大写,Case后面有空格,多多留心。
  3. 注意return 0;
  4. 牢记
#include <cstdio>
int main(){
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值