题目描述:给定区间[-2的31次方, 2的31次方]内的3个整数A、B和C,请判断A+B是否大于C。
输入:输入第1行给出正整数T(<=10),是测试用例的个数。随后给出T组测试用例,每组占一行,顺序给出A、B和C。整数间以空格分隔。
输入例子:
4
1 2 3
2 3 4
2147483647 0 2147483646
0 -2147483648 -2147483647
输出:对每组测试用例,在一行中输出“Case #X: true”如果A+B>C,否则输出“Case #X: false”,其中X是测试用例的编号(从1开始)。
Case #1: false
Case #2: true
Case #3: true
Case #4: false
考察各个数据类型所占的字节数,考虑溢出
字节数:https://blog.csdn.net/qq_26460841/article/details/82929931
方法一:python
n = int(input())
for i in range(n):
num = raw_input().split(' ')
if int(num[2])-int(num[0]) < int(num[1]):
print('Case #' + str(i+1) + ': true')
else:
print('Case #' + str(i+1) + ': false')
四行python
链接:https://www.nowcoder.com/questionTerminal/33ceeced8acc475aa0be9603936890a6
来源:牛客网
a=int(input())
for i in range(a):
b,c,d=map(int,input().split())
print("Case #"+str(i+1)+": true" if b+c>d else "Case #"+str(i+1)+": false")
方法二:java
Java获取输入:https://www.cnblogs.com/2206411193qzb/p/7348637.html
链接:https://www.nowcoder.com/questionTerminal/33ceeced8acc475aa0be9603936890a6
来源:牛客网
作者:smileboy
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i = 0 ;
int num = 0;
long a,b,c;
a = 0;
b = 0;
c = 0;
num = sc.nextInt();
while(i++<num){
a = sc.nextLong();
b = sc.nextLong();
c = sc.nextLong();
if((a+b)>c){
System.out.println("Case #"+i+": true");
}
else{
System.out.println("Case #"+i+": false");
}
}
}
}