1065. A+B and C (64bit) (20)

本文探讨了如何在给定整数范围内的三个整数时,判断两个整数之和是否大于第三个整数的问题。通过实例分析,阐述了在不同条件下如何正确进行加法操作和比较,避免溢出错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C.

Input Specification:

The first line of the input gives the positive number of test cases, T (<=10).  Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.

Output Specification:

For each test case, output in one line "Case #X: true" if A+B>C, or "Case #X: false" otherwise, where X is the case number (starting from 1). 

Sample Input:
3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0
Sample Output:
Case #1: false
Case #2: true
Case #3: false

 思路:根据是否溢出来做 ,但是好郁闷    arr[i].a+arr[i].b作为整体时就出错! long long total = arr[i].a+arr[i].b;  用total代替就OK' 真心搞不懂啊!!

AC代码:

#include <iostream>
using namespace std;
int N;
struct Node{
    long long a;
    long long b;
    long long c;
};
Node arr[11];
int main()
{
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>arr[i].a>>arr[i].b>>arr[i].c;
        long long total = arr[i].a+arr[i].b;
        if(arr[i].a<0 && arr[i].b<0 && total>=0){   //发生溢出
            cout<<"Case #"<<i+1<<": "<<"false"<<endl;
        }else if(arr[i].a>0 && arr[i].b>0 && total<=0){
            cout<<"Case #"<<i+1<<": "<<"true"<<endl;
        }else{
            if(total>arr[i].c){
                cout<<"Case #"<<i+1<<": "<<"true"<<endl;
            }else{
                cout<<"Case #"<<i+1<<": "<<"false"<<endl;
            }
        }
    }
    return 0;
}


 

Error: Problem: package policycoreutils-python-utils-2.9-19.el8.noarch requires /usr/libexec/platform-python, but none of the providers can be installed - package container-selinux-2:2.179.1-1.module+el8.6.0+785+d1251653.noarch requires policycoreutils-python-utils, but none of the providers can be installed - package platform-python-3.6.8-45.el8.rocky.0.i686 requires python3-libs(x86-32) = 3.6.8-45.el8.rocky.0, but none of the providers can be installed - package platform-python-3.6.8-45.el8.rocky.0.i686 requires libpython3.6m.so.1.0, but none of the providers can be installed - package platform-python-3.6.8-45.el8.rocky.0.x86_64 requires libpython3.6m.so.1.0()(64bit), but none of the providers can be installed - package platform-python-3.6.8-45.el8.rocky.0.x86_64 requires python3-libs(x86-64) = 3.6.8-45.el8.rocky.0, but none of the providers can be installed - package containerd.io-1.6.28-3.1.el8.x86_64 requires container-selinux >= 2:2.74, but none of the providers can be installed - installed package python3-3.7.4-8.oe1.x86_64 obsoletes python3-libs provided by python3-libs-3.6.8-45.el8.rocky.0.i686 - installed package python3-3.7.4-8.oe1.x86_64 obsoletes python3-libs provided by python3-libs-3.6.8-45.el8.rocky.0.x86_64 - conflicting requests - problem with installed package python3-3.7.4-8.oe1.x86_64 - package container-selinux-2:2.124.0-1.gitf958d0c.module+el8.5.0+681+c9a1951f.noarch is excluded - package container-selinux-2:2.130.0-1.module+el8.5.0+770+e2f49861.noarch is excluded - package container-selinux-2:2.178.0-1.module+el8.6.0+784+32aef5de.noarch is excluded - package container-selinux-2:2.178.0-2.module+el8.6.0+783+10209741.noarch is excluded (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
最新发布
07-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值