首页 > 学院 > 开发设计 > 正文

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

2019-11-08 18:30:37
字体:
来源:转载
供稿:网友

涨了个知识, LLONG_MAX这种类似的常量是包含再climits这个头文件里的

#include<iostream>#include<climits>#PRagma warning (disable:4996)using namespace std;bool compare(long long int A, long long int B, long long int C){ if (A > 0 && B > 0 && A > LLONG_MAX - B) return true;//判断上溢出 if (A < 0 && B < 0 && A < LLONG_MIN - B) return false;//判断下溢出 else return A + B > C;//未出现溢出情况}int main(){ long long int A, B, C; int N; cin >> N; for (int t = 1;t <= N;t++) { scanf("%lld %lld %lld", &A, &B, &C); printf("Case #%d: ", t); if (compare(A, B, C)) printf("true/n"); else printf("false/n"); }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表