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

简介: Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C.

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:
3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0
Sample Output:
Case #1: false
Case #2: true
Case #3: false

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    scanf("%d", &n);
    long long a, b, c, sum;
    bool m[n];
    
    for (int i = 0; i < n; i++) {
        scanf("%lld %lld %lld", &a, &b, &c);
        sum = a + b;
        if (a > 0 && b > 0 && sum < 0) m[i] = true;
        else if (a < 0 && b < 0 && sum >= 0) m[i] = false;
        else if (sum > c) m[i] = true;
        else m[i] = false;
    }
    
    for (int i = 0; i < n; i++) {
        if (m[i]) {
            printf("Case #%d: true\n", i+1);
        }else{
            printf("Case #%d: false\n", i+1);
        }
    }
    
    return 0;
}



目录
相关文章
|
3月前
|
存储 网络协议 C语言
一文带你秒懂 字节序(byte order),比特序(bit order),位域(bit field)
一文带你秒懂 字节序(byte order),比特序(bit order),位域(bit field)
52 0
|
6月前
|
存储 Java 编译器
BIT-4指针(9000字详解)
BIT-4指针(9000字详解)
38 0
|
6月前
|
存储 C语言
BIT-5数据在内存中的存储及字符函数(10000字详解)
BIT-5数据在内存中的存储及字符函数(10000字详解)
56 0
|
6月前
|
存储 Go
1bit等于多少字节?换算方法详解
1bit等于多少字节?换算方法详解
245 0
|
8月前
|
存储
位(bit) \字节(byte)\十六进制
位(bit) \字节(byte)\十六进制
|
9月前
|
编译器
整数溢出机制 C
整数溢出机制 C
221 0
|
存储
用补码计算x+y,并判断结果是否溢出问题
浮点数的加减法与是否溢出的判断,是计算机组成原理中的数据存储的一个入门。至于溢出情况,如果01就是正溢出,00,11未溢出,10负溢出。
390 0
用补码计算x+y,并判断结果是否溢出问题
Bit++
Bit++
171 0
Bit++
|
存储 安全 编译器
浅谈溢出问题
在c语言或是c++中有一类很典型的问题,那就是溢出。 如果说溢出对程序有什么危害的话,好像就是在编译的时候会报错,运行的时候会崩溃。但是当有了研究安全的人之后,安全性问题就会随之出现了。
浅谈溢出问题

热门文章

最新文章