A1065——入门模拟 A+B and C

2019-12-18

21:31:22

 

注意需要用变量单独来记录 a + b的值,和正溢出和负溢出的情况。

#include <bits/stdc++.h>
#include<math.h>
using namespace std;
const int MAXN = 100005;
int main(){
    int n = 0;
    cin>>n;
    bool temp[n+1];
    for(int i=1;i<n+1;++i){
        temp[i] = 0;
    }
    for(int i=1;i<n+1;++i){
        long long a = 0,b=0,c= 0;
        cin>>a;
        cin>>b;
        cin>>c;
        long long t = a+b;
        if(a<0&&b<0&&t>=0){//负溢出 
            temp[i] = 0;
            //continue;
        }
        else if(a>0&&b>0&&t<0){//正溢出 
            temp[i] = true;
            //continue;
        }
        else if(t>c){
            temp[i] = 1;
        }
        if(temp[i]==0){
            printf("Case #%d: false\n",i);
        }
        if(temp[i]==true){
            printf("Case #%d: true\n",i);
        }
        
    }
    /*for(int i =0;i<n;++i){
        if(temp[i]==0){
            printf("Case #%d:false\n",i);
            continue;
        }
        if(temp[i]==true){
            printf("Case #%d:true\n",i);
        }
    }*/
    system("pause");
    return 0;
} 
posted @ 2019-12-18 21:33  JasonPeng1  阅读(240)  评论(0编辑  收藏  举报