题解 | #A + B Is Overflow#
A + B Is Overflow
https://ac.nowcoder.com/acm/problem/14321
题目描述
Judge whether the sum of A and B will exceed the range of 32-bit signed integer.
输入描述:
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, 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".
如果int(a+b)等于long long(a+b),则a与b的和不爆int
#include<iostream> using namespace std; int main() { int t; cin>>t; long long a,b; while(t--) { cin>>a>>b; int sum=a+b; if(sum==a+b) cout<<"No"<<endl; else cout<<"Yes"<<endl; } return 0; }