码迷,mamicode.com
首页 > 其他好文 > 详细

1065 A+B and C (64bit) (20 分)

时间:2021-03-10 13:11:02      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:items   思路   word   tst   lex   ++   cat   star   def   

题目描述

1065 A+B and C (64bit) (20 分)
 

Given three integers A, B and C in [?], 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 (≤). 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
思路:不想写大数,看人家的题解知道的,long long数据范围内直接算不得行,但是如果ll正数超界了会变为负数,相当于环,负数超界了会变为正数
代码:
#include<iostream>
#include<string.h>
#include<cmath>
#include<set>
#include<map>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
#include<algorithm>
#include<climits>
using namespace std;
typedef long long ll;
inline ll read() {
    ll sum = 0, f = 1;
    char p = getchar();
    for (; !isdigit(p); p = getchar()) if (p == -)f = -1;
    for (; isdigit(p); p = getchar())  sum = sum * 10 + p - 48;
    return sum * f;
}
const int maxn = 10001;
int main() {
    int t = read();
    ll a, b, c, sum;
    for (int i = 1; i <= t;i++) {
        printf("Case #%d: ");
        scanf("%lld%lld%lld", &a, &b, &c);
        sum = a + b;
        if (a > 0 && b > 0 && sum < 0)printf("true\n");
        else if (a < 0 && b < 0 && sum>0)printf("false\n");
        else if (sum > c) {
            printf("true\n");
        }
        else {
            printf("false\n");
        }
    }
    return 0;
}

 

1065 A+B and C (64bit) (20 分)

标签:items   思路   word   tst   lex   ++   cat   star   def   

原文地址:https://www.cnblogs.com/MYMYACMer/p/14507666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!