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 ...
随机推荐
- MultiSet
Guava引进了JDK里没有的,但是非常有用的一些新的集合类型.所有这些新集合类型都能和JDK里的集合平滑集成.Guava集合非常精准地实现了JDK定义的接口.Guava中定义的新集合有: Multi ...
- WebView(网络视图)的两种使用方式
WebView(网络视图)能加载显示网页,可以将其视为一个浏览器.它使用了WebKit渲染引擎加载显示网页,实现WebView有以下两种不同的方法:第一种方法的步骤:1.在要Activity中实例化W ...
- SPOJ DISUBSTR Distinct Substrings 后缀数组
题意:统计母串中包含多少不同的子串 然后这是09年论文<后缀数组——处理字符串的有力工具>中有介绍 公式如下: 原理就是加上新的,减去重的,这题是因为打多校才补的,只能说我是个垃圾 #in ...
- FOJ 1858 Super Girl 单调队列
http://acm.fzu.edu.cn/problem.php?pid=1858 一个数组中 找两对元素,第一对元素和最大,第二对元素和最小,限制:一对元素中两个元素的距离在原数组中小于d.去掉 ...
- 《Python 学习手册4th》 第十六章 函数基础
''' 时间: 9月5日 - 9月30日 要求: 1. 书本内容总结归纳,整理在博客园笔记上传 2. 完成所有课后习题 注:“#” 后加的是备注内容 (每天看42页内容,可以保证月底看完此书) “重点 ...
- Selenium IDE测试创建
Selenium IDE 测试创建 涉及使用IDE Selenium创建测试,如下面的步骤 记录和测试添加命令 保存测试记录 保存测试程序 执行测试记录 在测试中记录和添加命令 为了演示目的,我们将利 ...
- 结合Vim ghostscript 将源代码文件转换成语法高亮的pdf格式文档
step 1: 安装ghostscript (debian 环境, 其他环境自行google) sudo apt-get install ghostscript step 2: 用Vim生成ps文件 ...
- TCPSocket v1.0 for cocos2d-x下载
下载地址:http://files.cnblogs.com/elephant-x/TCPSocketLibs_V1.0.rar 这是自己封装的一个TCPSOCKET包,是独立于cocos2d-x的,使 ...
- Java中可重入锁ReentrantLock原理剖析
本文由码农网 – 吴极心原创,转载请看清文末的转载要求,欢迎参与我们的付费投稿计划! 一. 概述 本文首先介绍Lock接口.ReentrantLock的类层次结构以及锁功能模板类AbstractQue ...
- JSF 2.0 + Ajax hello world example
In JSF 2.0, coding Ajax is just like coding a normal HTML tag, it's extremely easy. In this tutorial ...