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

题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1065

思路分析:

 1)对a+b造成的long long 类型的数据溢出进行特殊处理:

  a>0 && b>0 && a+b<=0 :则a+b必大于c

  a<0 && b<0 && a+b>=0 :则a+b必小于c

 

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 
 5 int main(int argc,char *argv[]){
 6     long long a,b,res;
 7 
 8     int n;
 9     scanf("%d",&n);
10     bool flag;
11     for(int i=1;i<=n;i++){
12         scanf("%lld %lld %lld",&a,&b,&res);
13         long long tmp=a+b;
14 
15         if(a>0 && b>0 && tmp<=0)flag=true;
16         else if(a<0 && b<0 && tmp>=0) flag=false;
17         else flag=a+b>tmp;
18 
19         printf("Case #%d:",i);
20         if(flag) puts("true");
21         else puts("false");
22     }
23 
24     system("pause");
25     return 0;
26 }

 

posted @ 2014-08-18 15:11  晓风_7  阅读(171)  评论(0编辑  收藏  举报