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 ...
随机推荐
- 问题-[Delphi]MainFrame.pas(4340): E2036 Variable required
问题现象:写了一个TObjectList的Sort方法,但是写成ObjectList.Sort(@SortBridgeEDOReportQtys); 再F9时提示“E2036 Variable req ...
- A Tour of Go Struct Fields
Struct fields are accessed using a dot. package main import "fmt" type Vertex struct { X i ...
- 【三支火把】---C指针总结
好久没写博客了,重新学习C语言了的基础课程,发现很多东西都忘记的差不多了,闲来无事,总结一下关于指针的知识,希望能帮到像我一样的菜鸟们: 指针,众所周知是C语言的精华所在,不懂指针的话,你就不要说你学 ...
- spring boot 数据库连接池配置
HikariCP 连接池配置: http://stackoverflow.com/questions/29650501/hikaricp-starts-when-mvn-spring-bootrun- ...
- Hyper-V避免使用快照
虽然Hyper-V快照好处多多,但应该尽量少用,有两个原因,首先,如果你创建的是数据库服务器快照,你必须执行回滚,这样数据库往往会招到破坏,其次,创建快照会影响虚拟机的性能,实际上,创建快照就是创建第 ...
- android101 获取、备份、插入短信
package com.itheima.getsms; import java.io.File; import java.io.FileNotFoundException; import java.i ...
- 在Android应用程序使用YouTube API来嵌入视频
在Android版YouTube播放器API使您可以将视频播放功能到你的Android应用程序.该API允许您加载和播放YouTube视频(和播放列表),并自定义和控制视频播放体验. 您可以加载或暗示 ...
- freewrap——将tcl/tk脚本转变为可执行文件
FreeWrap可以把TCL/TK的脚本和二进制文件打包成应用程序,FreeWrap将所有的文件组合成一个单独的可执行文件. FreeWrap的原理是把脚本和tcl/tk解释器和库文件都打包 ...
- Ubuntu server搭建vsftpd小记
Ubuntu server中搭建vsftpd小记 <h1> 在Ubuntu server中安装vsftpd</h1> sudo apt-get install vsftpd & ...
- mysql 备份还原数据库
备份和还原都在bin目录下操作 1.备份 mysqldump -u 用户名 -p 密码 --default-character-set=utf8 数据库名称 >d:/temp.sql 2.还 ...