判断整数A+B>C

【PAT B1011】
题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805312417021952

注意点:
(1)要注意数据类型。int表示的范围是-2^31 ~2^31-1,所以不能用int,而且A+B的范围可能超过int,所以得用long long。

整数范围速查:
char -128 ~ +127 (1 Byte)
short -32767 ~ + 32768 (2 Bytes)
unsigned short 0 ~ 65536 (2 Bytes)
int -2147483648 ~ +2147483647 (4 Bytes)
unsigned int 0 ~ 4294967295 (4 Bytes)
long == int
long long -9223372036854775808 ~ +9223372036854775807 (8 Bytes)
double 1.7 * 10^308 (8 Bytes)

(2)注意输出格式。注意Case后面有个空格,#X:后面还有个空格。最后一行结束不要再加换行。

代码:

#include<iostream>
using namespace std;

int main()
{
	int T;
	int n;
	cin >> T;
	long long* A = new long long[T];
	long long* B = new long long[T];
	long long* C = new long long[T];
	for (n = 0; n < T; ++n)
	{
		cin >> A[n] >> B[n] >> C[n];
	}
	for (n = 0; n < T; ++n)
	{
		if(A[n]+B[n] >C[n])
			cout << "Case #" << n+1 << ": true";
		else
			cout << "Case #" << n+1 << ": false";

		if (n < T-1)
			cout << endl;
	}

	return 0;
}
posted @ 2021-01-27 10:23  MorpheusDong  阅读(211)  评论(0编辑  收藏  举报