题解 | #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, 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;
}


全部评论

相关推荐

点赞 评论 收藏
分享
吃不饱的肱二头肌很想退休:tnnd 我以为选妹子呢,亏我兴高采烈的冲进来😠
投递快手等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务