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

来源:互联网 发布:闭合水准测量记录数据 编辑:程序博客网 时间:2024/06/06 08:34

1065. A+B and C (64bit) (20)

时间限制
100 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
HOU, Qiming

Given three integers A, B and C in [-263, 263], you are supposed to 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 line containing 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>C, or "Case #X: false" otherwise, where X is the case number (starting from 1).

Sample Input:
31 2 32 3 49223372036854775807 -9223372036854775808 0
Sample Output:
Case #1: falseCase #2: trueCase #3: false

提交代码


狂汗不已。。每次都要初始化flag标签!放错位置,耽误好几个小时,弄得心情不爽。。


#include<stdio.h>int main(){int i,n;while(scanf("%d",&n)!=EOF){          long long int a,b,c,tmp;for(i=1;i<=n;i++){scanf("%lld %lld %lld",&a,&b,&c);tmp=a+b;                 int flag=0;  //对于每一组输入都要重置flagif(a>0 && b>0 && a+b<=0)flag=1;else if(a<0 && b<0 && a+b>=0)flag=0;else{if(tmp>c)   //必须要算出来 后才比较,不然只有12分。。。。。。。。。。。。flag=1;}printf("Case #%d: ",i);if(flag==1)printf("true\n");elseprintf("false\n");}}    return 0;}


0 0
原创粉丝点击