美文网首页
2019-08-05 1065 A+B and C

2019-08-05 1065 A+B and C

作者: JO炮 | 来源:发表于2019-08-05 20:03 被阅读0次

这道题其实是很简单的,但是还是会有想的不周到的点在里面,比如我就是在看了柳神的代码之后才知道自己在溢出这个点想的不够充分,导致无法ac,在柳神的刷题指导里已经写出:

在int * int和int + int的过程中都有可能出现结果超过了int而产生溢出的情况.

这个点也不是什么难点但是我就是没想到。

#include <iostream>
using namespace std;
int main() {
    int t; 
    scanf("%d", &t);
    long long a,b,c;
    long long sum = 0;
    for(int i = 0; i < t; i ++){
        scanf("%lld %lld %lld", &a, &b, &c);
        sum = a + b;
        if( a < 0 && b < 0 && sum > 0)
        printf("case #%d: false\n", i + 1);
        else if( a > 0 && b > 0 && sum < 0)
        printf("case #%d: true\n", i + 1);
        else if(sum > c)
        printf("case #%d: true\n", i + 1);
        else
        printf("case #%d: false\n", i + 1);
        
    }
    return 0;
}

相关文章

网友评论

      本文标题:2019-08-05 1065 A+B and C

      本文链接:https://www.haomeiwen.com/subject/zusvdctx.html