NC14321. A + B Is Overflow
描述
输入描述
There are multiple test cases. The first line of each test case is a positive integer T, indicating the number of test cases.
For each test case, there is only one line including two 32-bit signed integers A and B.
输出描述
For each test case, output one line. If the sum of A and B will exceed the range of integer, print "Yes", else print "No".
示例1
输入:
3 1 2 -2147483648 2147483647 2147483647 2147483647
输出:
No No Yes
C(clang 3.9) 解法, 执行用时: 1ms, 内存消耗: 296K, 提交时间: 2020-07-26 10:55:52
# include <stdio.h> int main(){ long long int a,b; int n,i=0,s; scanf("%d",&n); for(;i<n;i++){ scanf("%lld %lld",&a,&b); s=a+b; printf("%s\n",(s-a)!=b?"Yes":"No"); } return 0; }
C++(g++ 7.5.0) 解法, 执行用时: 3ms, 内存消耗: 384K, 提交时间: 2022-12-01 21:25:55
#include<bits/stdc++.h> using namespace std; int main(){ int a; cin>>a; long long c,d; while(a--){ cin>>c>>d; int sum=c+d; if(c+d==sum) cout<<"No"<<endl; else cout<<"Yes"<<endl; } }
Python3 解法, 执行用时: 38ms, 内存消耗: 4500K, 提交时间: 2022-10-22 18:25:44
T=int(input()) for _ in range(T): a,b=map(int,input().split()) if((a+b)>-2147483648 and (a+b)<2147483648): print('No') else:print('Yes')