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


全部评论

相关推荐

06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
07-01 23:23
郑州大学 Java
否极泰来来来来:牛客迟早有高三的
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 11:33
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务