ZJU-PAT 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.
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
分析: 1.考虑相加溢出的情况 (1) a > 0 && b>0 && a+b <0 , 因 a+b > c,故true (2) a < 0 && b<0 && a+b >0 , 因 a+b < c,故false 2. PAT上不支持 __int64数据,採用long long型数据
#pragma warning (disable:4786)
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std; int main()
{
int T;
cin>>T;
for(int i=1;i<=T;i++)
{
long long int a,b,c;
cin>>a>>b>>c; cout<<"Case #"<<i+1<<": "; bool flag;
long long ans =a+b;
if(a>0 && b>0 && ans<=0)
flag=true;
else if(a<0 && b <0 && ans >= 0)
flag=false;
else
flag = (ans > c);
if(flag)
cout<<"true"<<endl;
else
cout<<"false"<<endl;
}
return 0;
}
ZJU-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)
1065 A+B and C (64bit) (20 分) Given three integers A, B and C in [−], you are supposed to tell whe ...
- 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 分)(溢出判断)*
1065 A+B and C (64bit) (20 分) Given three integers A, B and C in [−], you are supposed to tell whe ...
- pat 1065 A+B and C (64bit)(20 分)(大数, Java)
1065 A+B and C (64bit)(20 分) Given three integers A, B and C in [−263,263], you are supposed t ...
- PAT 甲级 1065. A+B and C (64bit) (20) 【大数加法】
题目链接 https://www.patest.cn/contests/pat-a-practise/1065 思路 因为 a 和 b 都是 在 long long 范围内的 但是 a + b 可能会 ...
- 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 (Advanced Level) 1065. A+B and C (64bit) (20)
因为会溢出,因此判断条件需要转化.变成b>c-a #include<cstdio> #include<cstring> #include<cmath> #in ...
- PAT甲题题解-1065. A+B and C (64bit) (20)-大数溢出
第一眼以为是大数据,想套个大数据模板,后来发现不需要.因为A.B.C的大小为[-2^63, 2^63],用long long 存储他们的值和sum. 接下来就是分类讨论:如果A > 0, 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 ...
随机推荐
- [Everyday Mathematics]20150127
设 $f,g:[a,b]\to [0,\infty)$ 连续, 单调递增, 并且 $$\bex \int_a^x \sqrt{f(t)}\rd t\leq \int_a^x \sqrt{g(t)}\r ...
- 对delegate进行扩展 打造通用的"计时完成"方法 z
让用户尽量少打字 每次让用户输入这么多信息的确很糟糕, 可以改进一下设计: 服务器IP和用户名可以存放在配置文件里面, 初始化的时候默认加载到相应的文本框中; 从安全角度考虑, 密码必须经过用户手动输 ...
- HDU5779 Tower Defence (BestCoder Round #85 D) 计数dp
分析(官方题解): 一点感想:(这个题是看题解并不是特别会转移,当然写完之后看起来题解说得很清晰,主要是人太弱 这个题是参考faebdc神的代码写的,说句题外话,很荣幸高中和faebdc巨一个省,虽然 ...
- 使用PPA在ubuntu上安装emacs
使用PPA(Personal Package Archive)在ubuntu上安装emacs 1添加 PPA 到 apt repository 中: $ sudo add-apt-reposito ...
- lighttpd mod_status模块
用过nginx的status可以查看服务器的状态,之后就想lighttpd有没有这样的模块呢 之后看下配置文件,真的有,然后就试下 第一步, "mod_auth" 把这个前面的#号 ...
- CentOS6 搭建git
rpm -qa | grep zlib-devel 查看是否安装过 ----------------------------------------------------------------- ...
- MFC学习知识点20160715
1. sizeof() :返回所查询目标所占用字节数 _countof() :返回所查询目标所含有元素个数 _countof 是 C++中计算一个固定大小数组长度的宏,比如: T arr[10] ...
- 重新执笔,已是大三!Jekyll自定义主题开发
前言 “一转眼忘了时间 丢了感觉 黑了世界 再逞强 再疯狂 也会伤 不知 不觉 后知 后觉 然后 发现 失去 知觉 ”——<一吻不天荒> 感言 时间是把双刃剑,什么解决不了,忧烦的,慢慢变 ...
- hive-mysql安装配置
默认情况下,hive的元数据信息存储在内置的Derby数据中.Facebook将hive元数据存储在关系数据库 1.安装好mysql ,sudo apt-get install mysql-serve ...
- virt viewer Usbredir USB重定向
编译virt viewer之前执行的configure命令,是没有使能usb-redir相关的功能,virt viewer是否支持usbredir是完全依赖于spice-gtk的. virt view ...