zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    每日总结
    每日总结
    每日总结
    每日总结
    每周总结
    每日总结
    10.20
    10.19
    10.18
    10.17
  • 原文地址:https://www.cnblogs.com/sixue/p/3919594.html
Copyright © 2011-2022 走看看