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

Given three integers A, B and C in [−], 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 (≤). 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

题解:

没有这样去考虑,没做对

因为A、B的大小为[-2^63, 2^63],用long long 存储A和B的值,以及他们相加的值sum:
如果A > 0, B < 0 或者 A < 0, B > 0,sum是不可能溢出的
如果A > 0, B > 0,sum可能会溢出,sum范围理应为(0, 2^64 – 2],溢出得到的结果应该是[-2^63, -2]是个负数,所以sum < 0时候说明溢出了

如果A < 0, B < 0,sum可能会溢出,同理,sum溢出后结果是大于0的,所以sum > 0 说明溢出了

AC代码:

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
long long a,b,c,sum;
int main(){
int n;
cin>>n;
for(int i=;i<=n;i++){
cin>>a>>b>>c;
sum=a+b;
if(a>&&b>&&sum<=){
cout<<"Case #"<<i<<": "<<"true"<<endl;
}else if(a< &&b< &&sum>=){
cout<<"Case #"<<i<<": "<<"false"<<endl;
}else if(sum>c){
cout<<"Case #"<<i<<": "<<"true"<<endl;
}else{
cout<<"Case #"<<i<<": "<<"false"<<endl;
}
}
return ;
}

PAT 甲级 1065 A+B and C (64bit) (20 分)(溢出判断)*的更多相关文章

  1. pat 甲级 1065. A+B and C (64bit) (20)

    1065. A+B and C (64bit) (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming G ...

  2. PAT 甲级 1065. A+B and C (64bit) (20) 【大数加法】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1065 思路 因为 a 和 b 都是 在 long long 范围内的 但是 a + b 可能会 ...

  3. PAT Advanced 1065 A+B and C (64bit) (20 分)(关于g++和clang++修改后能使用)

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

  4. PAT甲级:1124 Raffle for Weibo Followers (20分)

    PAT甲级:1124 Raffle for Weibo Followers (20分) 题干 John got a full mark on PAT. He was so happy that he ...

  5. PAT甲级——1065 A+B and C (64bit)

    1065 A+B and C (64bit) Given three integers A, B and C in [−2​63​​,2​63​​], you are supposed to tell ...

  6. 【PAT甲级】1065 A+B and C (64bit) (20 分)(大数溢出)

    题意: 输入三个整数A,B,C(long long范围内),输出是否A+B>C. trick: 测试点2包括溢出的数据,判断一下是否溢出即可. AAAAAccepted code: #defin ...

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

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

  8. PAT甲题题解-1065. A+B and C (64bit) (20)-大数溢出

    第一眼以为是大数据,想套个大数据模板,后来发现不需要.因为A.B.C的大小为[-2^63, 2^63],用long long 存储他们的值和sum. 接下来就是分类讨论:如果A > 0, B & ...

  9. PAT 甲级 1116. Come on! Let's C (20) 【循环判断】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1116 思路 注意一个细节 如果没有本来 ID 的 后来又查了这个ID 不是输出 checked ...

随机推荐

  1. java相关资料连接

    1.tomcat原理https://www.ibm.com/developerworks/cn/java/j-lo-tomcat1/index.html ....

  2. Linux PXE 网络装机

    一.基础网络建设 Linux配置静态IP-192.168.5.1 # vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ONBOOT= ...

  3. drf框架 - JWT认证插件

    JWT认证 JWT认证方式与其他认证方式对比: 优点 1) 服务器不要存储token,token交给每一个客户端自己存储,服务器压力小 2)服务器存储的是 签发和校验token 两段算法,签发认证的效 ...

  4. 棋盘覆盖 状压DP+矩阵快速幂

    题意:有一个m 行n 列的矩形方格棋盘,1 < = m< = 5,1=< n< =10^9,用1*2 的骨牌(可横放或竖放)完全覆盖,骨牌不能重叠,有多少种不同的覆盖的方法.你 ...

  5. LightOJ - 1294 - Positive Negative Sign(规律)

    链接: https://vjudge.net/problem/LightOJ-1294 题意: Given two integers: n and m and n is divisible by 2m ...

  6. 交互设计算法基础(3) - Quick Sort

    int pivotIndex, pivot, swapIndex; void swap(int[] arr, int x, int y) { int temp = arr[x]; arr[x] = a ...

  7. Pytest权威教程21-API参考-04-钩子(Hooks)

    目录 钩子(Hooks) 引导时的Hook方法 初始化时的Hook方法 测试运行时的Hook方法 收集用例时的Hook方法 生成测试结果时的Hook方法 调试/交互Hook方法 返回: Pytest权 ...

  8. 第12组 Alpha冲刺(1/6)

    Header 队名:To Be Done 组长博客 作业博客 团队项目进行情况 燃尽图(组内共享) 展示Git当日代码/文档签入记录(组内共享) 注: 由于GitHub的免费范围内对多人开发存在较多限 ...

  9. finnal关键字修饰

    1.修饰变量,被赋值后不能被赋其他值,相当于常量 2.修饰方法,该方法不可以被子类重写,但可以重载 3.修饰类,修饰的类不可以被继承,如String,Math等

  10. 教你怎样用fluent长网格【转载】

    转载地址: http://blog.sina.cn/dpool/blog/s/blog_63a80e870100k1jo.html?type=-1 有的时候,当你十月怀胎,千辛万苦把网格生出来,导入f ...