1065 A+B and C (64bit) (20 分)
标签:items 思路 word tst lex ++ cat star def
题目描述
Given three integers A, B and C in [?], you are supposed to tell whether A+B>C.
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.
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).
3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0
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; }
标签:items 思路 word tst lex ++ cat star def
原文地址:https://www.cnblogs.com/MYMYACMer/p/14507666.html