PAT.1011. A+B和C

题目

时间限制
150 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
HOU, Qiming
给定区间[-231, 231]内的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

分析:

输入比大小,注意范围

代码(java)

package b1011;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for(int i=1;i<=n;i++) {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            if(a+b>c)
                System.out.println("Case #" + i + ": true");
            else
                System.out.println("Case #" + i + ": false");
        }
        in.close();
    }

}

代码(cpp)

#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        long a,b,c;
        cin>>a>>b>>c;
        if(a+b>c)
            cout<<"Case #"<<i<<": true"<<endl;
        else
            cout<<"Case #"<<i<<": false"<<endl;
    }
    return 0;
}
全部评论

相关推荐

码砖:求职岗位要突出,一眼就能看到,教育背景放到最后,学校经历没那么重要,项目要重点突出
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务