PAT 甲级 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 分)(溢出判断)*的更多相关文章
- 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 ...
- PAT 甲级 1065. A+B and C (64bit) (20) 【大数加法】
题目链接 https://www.patest.cn/contests/pat-a-practise/1065 思路 因为 a 和 b 都是 在 long long 范围内的 但是 a + b 可能会 ...
- 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 ...
- 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 ...
- PAT甲级——1065 A+B and C (64bit)
1065 A+B and C (64bit) Given three integers A, B and C in [−263,263], you are supposed to tell ...
- 【PAT甲级】1065 A+B and C (64bit) (20 分)(大数溢出)
题意: 输入三个整数A,B,C(long long范围内),输出是否A+B>C. trick: 测试点2包括溢出的数据,判断一下是否溢出即可. AAAAAccepted code: #defin ...
- 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 ...
- PAT甲题题解-1065. A+B and C (64bit) (20)-大数溢出
第一眼以为是大数据,想套个大数据模板,后来发现不需要.因为A.B.C的大小为[-2^63, 2^63],用long long 存储他们的值和sum. 接下来就是分类讨论:如果A > 0, B & ...
- PAT 甲级 1116. Come on! Let's C (20) 【循环判断】
题目链接 https://www.patest.cn/contests/pat-a-practise/1116 思路 注意一个细节 如果没有本来 ID 的 后来又查了这个ID 不是输出 checked ...
随机推荐
- Vue 项目环境搭建
Vue项目环境搭建 ''' 1) 安装node 官网下载安装包,傻瓜式安装:https://nodejs.org/zh-cn/ 2) 换源安装cnpm >: npm install -g cnp ...
- ldap系列-基础知识
来源:关键字排名 ldap 是什么? LDAP(Lightweight Directory Access Protocol)即轻量级目录访问协议,提供信息服务.那啥是目录服务呢? 目录服务是一种特殊的 ...
- NOIP 2017 PJ
T1:水 T2:水 T3:水 T4:水,二分+DP检测+单调队列优化,然而优化写炸了,还没暴力分高 所以爆炸 (民间)100 + 100 + 100 + 10 = 310 GAME OVER
- MySQL常用五大引擎的区别
MyISAM: 如果你有一个 MyISAM 数据表包含着 FULLTEXT 或 SPATIAL 索引,你将不能把它转换为使用 另一种引擎,因为只有 MyISAM 支持这两种索引. BLOB: 如果你有 ...
- Hi,this is May.
“山有木兮木有枝 心悦君兮君不知” 当一个现在的人正在思念过去的人,世间的一切也都会变成过去的样子. 声色的娱乐,本来就如闪电的光.击石的火.男女欢合不过埋香葬玉.赋别鹤离鸾之曲,臂膀一曲一伸的工夫罢 ...
- 02_SAE中创建数据表
Step1:进入新浪云应用数据库点击应用名称,进入到该应用管理界面,在数据库服务中点击“共享型MySQL”: 开启MySQL服务,使用PHPMyAdmin管理数据库,进入MySQL数据库管理界面: S ...
- PHP利用执行操作符;模拟shell命令
$out = `ls -la`; echo '<pre>'.$out.'</pre>'; 输出结果: total 10 drwxrwxrwx 1 root root 4096 ...
- codevs 1683 车厢重组
1683 车厢重组 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 白银 Silver 题目描述 Description 在一个旧式的火车站旁边有一座桥,其桥面可以绕河中心的桥 ...
- 如何修复GitKraken Inotify Limit Error\idea erro - 升级Ubuntu / Linux inotify限制
GitKraken是一个非常优秀的Git客户端.如果您是软件开发人员,那么您绝对应该试试GitKraken.今天我去了我的一个存储库做了一些提交,但是GitKraken告诉我它已经得到了Inotify ...
- Java GUI:将JPanel添加进JScrollPane
实现的目标: 因为在滚动框中含有很多个Java GUI 组件,因此这里采用JPanel面板包住这些组件,在用JScrollPane实现滚动 问题1:布局揉在一起 JPanel有自己默认的布局方式,因此 ...