PAT 1065 a+b>c 64bit 翻译 分析 代码

题目:1065 a+b>c 64bit (20)(20 分)【加值溢出】

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

【给出三个整数A,B,C,三者均有限制,[-2^63^, 2^63],判断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 line containing three integers A, B and C, separated by single spaces.

【第一行给出整数T,表明T组数据。每行数据都包括A,B,C 期间被空格隔开】

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 from 1).

【如果 A+B > C ,输出Case #X: true;如果A+B < C ,输出Case #X: false 

【注】:以下分析所在为代码注释,通过注释可以分析得到此题答案。

【注】:此代码是由Dev c++ 5.11 所写,运用c++语言。  其他方法后续会另写博客给出方式。惊讶

#include<cstdio>
int main()
{

	int i,K;
	scanf("%d",&K);
	long long  a,b,c;  //长整数类型 
	bool jud;
	for(i=1;i<=K;i++)
	{
		scanf("%lld%lld%lld",&a,&b,&c);
		long long sum=a+b;			//二者加和值也必为长整数类型 
		if(a>0&&b>0&&sum<0) 		jud=true;		//a,b均为正数,且加值发生溢出,若溢出值为负数,则a+b>c; 
		else if(a<0&&b<0&&sum>=0)	jud=false;		//a,b均为负数,且加值发生溢出,若溢出值为正数,则a+b<c;
		else if(sum>c) 				jud=true;		//如果加值大于C,则说明没有溢出,且a+b>c; 
		else 						jud=false;		//其他情况,则为a+b<c; 
		if(jud==true)	printf("Case #%d: true\n", i);       //如果判断值为正,输出相应反应; 
		if(jud==false)	printf("Case #%d: false\n", i);      //如果判断值为负,输出相应反应; 
	}
	return 0;
 } //唱晚,我爱你  2018年7月2日17:29:57 

猜你喜欢

转载自blog.csdn.net/qq_42319613/article/details/80886790