PAT 1065 A+B and C (64bit) (20)
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
8
1 2 3
2 3 4
10 -10 0
101 -100 0
9223372036854775807 -9223372036854775808 0
9223372036854775808 9223372036854775808 1
9223372036854775808 -9223372036854775808 1
-9223372036854775808 -9223372036854775808 -1
ans:
Case #1: false
Case #2: true
Case #3: false
Case #4: true
Case #5: false
Case #6: true
Case #7: false
Case #8: false
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 0x7FFFFFFFFFFFFFFF;
const int MAXN = ;
const char str[MAXN] = "";
const char st[MAXN] = "-9223372036854775808"; char a[MAXN], b[MAXN], c[MAXN];
LL na, nb, nc, nd; int check( LL x ) { return x > ? : x < ? - : ; } int main() {
int t, cnt = ;
int ta, tb, tc, td;
bool fa, fb, fc;
scanf( "%d", &t );
while( t-- ) {
printf( "Case #%d: ", ++cnt );
scanf( "%s%s%s", a, b, c );
if( !strcmp( a, st ) && !strcmp( b, st ) ) {
puts( "false" ); continue;
}
fa = !strcmp( a, str );
fb = !strcmp( b, str );
fc = !strcmp( c, str );
if( !fa && !fb ) {
sscanf( a, "%I64d", &na ); ta = check( na );
sscanf( b, "%I64d", &nb ); tb = check( nb );
if( !fc ) { sscanf( c, "%I64d", &nc ); tc = check( nc ); }
nd = na + nb; td = check( nd );
if( ( ta * tb ) > && ( ta * td ) < ) {
if( ta > ) puts( "true" );
else puts( "false" );
} else {
if( fc ) puts( "false" );
else puts( nd > nc ? "true" : "false" );
}
} else {
ta = a[] == '-' ? - : a[] == '' ? : ;
tb = b[] == '-' ? - : b[] == '' ? : ;
if( fc ) {
if( !fa ) { swap( a, b ); swap( ta, tb ); swap( fa, fb ); }
if( tb <= ) puts( "false" );
else puts( "true" );
} else {
sscanf( c, "%I64d", &nc ); tc = check( nc );
if( ta ^ tb ) {
if( !fa ) { swap( a, b ); swap( ta, tb ); swap( fa, fb ); }
sscanf( b, "%I64d", &nb );
nd = INF + nb + ;
puts( nd > nc ? "true" : "false" );
} else puts( "true" );
}
}
}
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 分)(溢出判断)*
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)
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 ...
随机推荐
- 初次接触Android ActionBar比较烦人的问题[转]
本文转自:http://blog.csdn.net/u010933209/article/details/40112079 问题一:icon不能正常显示 一直都对actionbar又爱又恨,特别是刚接 ...
- Eclipse的下载、安装和WordCount的初步使用(本地模式和集群模式)
包括: Eclipse的下载 Eclipse的安装 Eclipse的使用 本地模式或集群模式 Scala IDE for Eclipse的下载.安装和WordCount的初步使用(本地模式和集群 ...
- PTA 08-图7 公路村村通 (30分)
现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本,求使每个村落都有公路连通所需要的最低成本. 输入格式: 输入数据包括城镇数目正整数NN(\le 1000≤1000)和候选道 ...
- [置顶] 项目进阶 之 持续构建环境搭建(二)Nexus私服器
上一篇博文项目进阶 之 持续构建环境搭建(一)架构中,我们大致讲解了一下本系列所搭建环境的基本框架,这次开始我们进入真正的环境搭建实战.重点不在于搭建的环境是否成功和完善,而是在搭建过程中充分认识到每 ...
- RHCA学习笔记:RH442-Unit9内核定时与进程延时
Unit 9 Kernel Timing and Process Latency 内核定时与进程延时 学习目标: A.了解CPU 是怎样追踪时间的 B.调整CPU的访问次数 C.调整调度延时 D. ...
- 标准I/O库之标准I/O的效率
程序清单5-1 用getc和putc将标准输入复制到标准输出 #include "apue.h" int main( void ) { int c; while(( c = get ...
- c# 可以有多个Main()函数
可以有多个Main()函数,这样写:namespace ConsoleApp1{class Program{static void Main(string[] args){Console.WriteL ...
- 动作之CCActionInstant(立即动作)家族
立即动作就是不需要时间,马上就完成的动作.立即动作的共同基类是CCActionInstant.CCActionInstant的常用子类有: CCCallFunc:回调函数包装器 CCFlipX:X轴翻 ...
- Cocos-2d 坐标系及其坐标转换
Cocos-2d中,涉及到4种坐标系: GL坐标系Cocos2D以OpenglES为图形库,所以它使用OpenglES坐标系.GL坐标系原点在屏幕左下角,x轴向右,y轴向上. 屏幕坐标系苹果的Quar ...
- linux shell read command-Getting User Input Via Keyboard--ref
ref:http://bash.cyberciti.biz/guide/Getting_User_Input_Via_Keyboard You can accept input from the ke ...