码迷,mamicode.com
首页 > 其他好文 > 详细

[PAT乙级题解]——A+B和C

时间:2018-03-13 22:47:56      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:sof   out   post   开始   编号   soft   for   new   name   

给定区间[-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


c++版:
#include<iostream>
using namespace std;

void no1(){
    int n;
    cin>>n;
    long A[n];
    long B[n];
    long C[n];
    for(int i = 0 ; i < n ; i++)
        cin>>A[i]>>B[i]>>C[i];
    for(int j = 0;j<n;j++){
        if(A[j]+B[j]>C[j])
            cout<<"Case #"<<j+1<<": true"<<endl;
        else
            cout<<"Case #"<<j+1<<": false"<<endl;
    }
}

 

Java版:

import java.util.Scanner;

public class Main {
    public void no1(){
        Scanner sc = new Scanner(System.in);
        int n;
        n = sc.nextInt();
        long A,B,C;
        A = 0;B = 0;C = 0;
        for(int i = 0 ; i < n ; i++){
            A = sc.nextLong();
            B = sc.nextLong();
            C = sc.nextLong();
            int j = i+1;
            if(A+B > C)
                System.out.println("Case #"+j+": true");
            else
                System.out.println("Case #"+j+": false");
        }
    }

    public static void main(String[] args) {
        Main main = new Main();
        main.no1();
    }

}

 

[PAT乙级题解]——A+B和C

标签:sof   out   post   开始   编号   soft   for   new   name   

原文地址:https://www.cnblogs.com/MoisAbby/p/8555890.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!