A1065 A+B and C (64bit) (20分)

Resolution:

  • a, b, c in the range of [-2 63 is 2 63 is ], but is long long [-2 63 is 2 63 is -1], when the range is greater than the sum will overflow and become negative.
  • So we need to be positive and negative overflow judgment.
#include <stdio.h>
int main(){
	int n,tc=1;
	scanf("%d",&n);
	while(n--!=0){
		long long a,b,c;
		scanf("%lld%lld%lld",&a,&b,&c);
		long long mm=a+b;
		bool flag=false;
		if(a>0&&b>0&&mm<0){flag=true;
		}else if(a<0&&b<0&&mm>=0){
			flag = false;
		}else if(mm>c) {flag =true;}
        if(flag==true)
		{printf("Case #%d: true\n",tc);
		}
		else printf("Case #%d: false\n",tc);
		tc++;
	}
}
Published 91 original articles · won praise 9 · views 10000 +

Guess you like

Origin blog.csdn.net/WeDon_t/article/details/105152157