PAT A 1065 A+B and C (64bit)

Given three integers A, B and C in [-2^63^, 2^63^], you are supposedto tell whether A+B > C.

Input Specification:

The first line of the input gives the positive number of test cases, T(<=10). Then T test cases follow, each consists of a single linecontaining three integers A, B and C, separated by single spaces.

Output Specification:

For each test case, output in one line "Case #X: true" if A+B&gtC, or"Case #X: false" otherwise, where X is the case number (starting from1).

Sample Input:

3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0

Sample Output:

Case #1: false
Case #2: true
Case #3: false
#include<cstdio>    //不要以为直接加就行了。。。还要考虑溢出的情况
int main() {
	int T, i = 1;
	scanf("%d", &T);
	while (T--) {
		long long a, b, c;
		scanf("%lld %lld %lld", &a, &b, &c);
		bool flag;
		long long res = a + b;
		if (a < 0 && b < 0 && res>=0) flag = false;    //这两个判断条件是计算机组成的知识。。。自己去推吧。。
		else if (a > 0 && b > 0 && res< 0)flag = true;
		else if (res > c) flag = true;        //a+b必须存放到long long型变量中,再去比较;直接比较会出错(我也不知道为啥。)
		else flag = false;
		if (flag == true)
			printf("Case #%d: true\n", i++);
		else printf("Case #%d: false\n", i++);
	}
	return 0;
}


猜你喜欢

转载自blog.csdn.net/joah_ge/article/details/80530120