1011. A+B和C (15)

1011. A+B和C (15)

时间限制
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
C++:
#include <iostream>
using namespace std;
int main()
{
	int T;
	cin>>T;
	bool *result = new bool [T];

	long double A,B,C;
	for(int i = 0;i<T;++i){
		cin>>A>>B>>C;
		result[i] = (A+B)>C?true:false;
	}
	for(int i =0;i<T;++i){
		cout<<"Case #"<<i+1<<": ";
		if(result[i])
			cout<<"true"<<endl;
		else 
			cout<<"false"<<endl; 
	}
	return 0;
}
 
Java:

import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
			Scanner input = new Scanner(System.in); 
			int T=input.nextInt();
			boolean[] result = new boolean [T];
			long A,B,C;
			for(int i = 0;i<T;++i){
				A = input.nextLong();
				B = input.nextLong();
				C = input.nextLong();
				result[i] = (A+B)>C?true:false;
			}
			for(int i =0;i<T;++i){
				System.out.print("Case #"+ (i+1) + ": ");
				if(result[i])
					System.out.println("true");
				else 
					System.out.println("false"); 
			}

		 
	}

}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值