zoukankan      html  css  js  c++  java
  • 1065 A+B and C (64bit) (20)(大数相加、正溢出、负溢出)

    正溢出:两个正数相加超过了该数据类型能表示的最大范围,结果为负数

    负溢出:两个负数相加超过了该数据类型能表示的最小范围,结果为正数包括零

    #include <algorithm>
    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <cstring>
    #include <vector>
    using namespace std;
    const int maxn = 0x3f3f3f3f;
    typedef long long ll;
    int main() {
        int t,k=0;
        ll a,b,c,sum;
        cin >>t;
        while(t--) {
            k++;
            cin >> a >> b >> c;
            sum = a + b;
            cout << "Case #" << k <<": " ;
            if(a > 0 && b > 0 && sum < 0) cout << "true" << endl;//如果A+B超过了longlong 那么一定大于C
            else if(a < 0 && b < 0 && sum >=0) cout << "false" << endl;//如果A+B超过了longlong最小值 那么一定小于C
            else if(sum > c) cout << "true" << endl;
            else  cout << "false" << endl;
        }
        return 0;
    }
  • 相关阅读:
    Java数据类型
    redis的安装
    软件测试(一、二)
    软件开发
    python----基础函数
    Python的web框架
    Python 中的lambda函数介绍
    Python中HTTP协议
    Django基本模块介绍
    Python --------列表
  • 原文地址:https://www.cnblogs.com/LLLAIH/p/11689505.html
Copyright © 2011-2022 走看看