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
代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const LL INF = 0x7FFFFFFFFFFFFFFF; 5 const int MAXN = 30; 6 const char str[MAXN] = "9223372036854775808"; 7 const char st[MAXN] = "-9223372036854775808"; 8 9 char a[MAXN], b[MAXN], c[MAXN]; 10 LL na, nb, nc, nd; 11 12 int check( LL x ) { return x > 0 ? 1 : x < 0 ? -1 : 0; } 13 14 int main() { 15 int t, cnt = 0; 16 int ta, tb, tc, td; 17 bool fa, fb, fc; 18 scanf( "%d", &t ); 19 while( t-- ) { 20 printf( "Case #%d: ", ++cnt ); 21 scanf( "%s%s%s", a, b, c ); 22 if( !strcmp( a, st ) && !strcmp( b, st ) ) { 23 puts( "false" ); continue; 24 } 25 fa = !strcmp( a, str ); 26 fb = !strcmp( b, str ); 27 fc = !strcmp( c, str ); 28 if( !fa && !fb ) { 29 sscanf( a, "%I64d", &na ); ta = check( na ); 30 sscanf( b, "%I64d", &nb ); tb = check( nb ); 31 if( !fc ) { sscanf( c, "%I64d", &nc ); tc = check( nc ); } 32 nd = na + nb; td = check( nd ); 33 if( ( ta * tb ) > 0 && ( ta * td ) < 0 ) { 34 if( ta > 0 ) puts( "true" ); 35 else puts( "false" ); 36 } else { 37 if( fc ) puts( "false" ); 38 else puts( nd > nc ? "true" : "false" ); 39 } 40 } else { 41 ta = a[0] == '-' ? -1 : a[0] == '0' ? 0 : 1; 42 tb = b[0] == '-' ? -1 : b[0] == '0' ? 0 : 1; 43 if( fc ) { 44 if( !fa ) { swap( a, b ); swap( ta, tb ); swap( fa, fb ); } 45 if( tb <= 0 ) puts( "false" ); 46 else puts( "true" ); 47 } else { 48 sscanf( c, "%I64d", &nc ); tc = check( nc ); 49 if( ta ^ tb ) { 50 if( !fa ) { swap( a, b ); swap( ta, tb ); swap( fa, fb ); } 51 sscanf( b, "%I64d", &nb ); 52 nd = INF + nb + 1; 53 puts( nd > nc ? "true" : "false" ); 54 } else puts( "true" ); 55 } 56 } 57 } 58 return 0; 59 }
View Code
转载于:https://www.cnblogs.com/Hitman_47/p/5185649.html
PAT 1065 A+B and C (64bit) (20)相关推荐
- PATA 1065 A+B and C (64bit) (20分)
PATA 1065 A+B and C (64bit) (20分) 题目描述:Given three integers A, B and C in [−2^63, 2^63], you are s ...
- 【PAT甲级 大数运算】1065 A+B and C (64bit) (20 分) Python 全部AC
题目 初学python,第一次用python刷oj,挑了个简单题试试手. 在大数运算方面,python没有数的大小限制,简直开挂. total = int(input()) for i in rang ...
- 【PAT甲级 大整数BigInteger】1065 A+B and C (64bit) (20 分) Java 全部AC
题目 在有些方面,比如大整数的处理,不得不佩服Java,好用没的说,像开挂一样 题解 Java import java.math.BigInteger; import java.util.Scanne ...
- 【详细讲解】1065 A+B and C (64bit) (20 分)
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given three integers A, B and C in [−2^63 ,2^63 ], you are ...
- PAT A1065 A+B and C (64bit) (20 分)
AC代码 #include <cstdio>int main() {#ifdef ONLINE_JUDGE#elsefreopen("1.txt", "r&q ...
- 1065 A+B and C (64bit) (20 分)【难度: 简单 / 思维 高精度】
https://pintia.cn/problem-sets/994805342720868352/problems/994805406352654336 方法一: 用高精度的板子写一下是可以的,不过 ...
- 1065 A+B and C (64bit)
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[大数运算][溢出]
1065 A+B and C (64bit)(20 分) Given three integers A, B and C in [−263,263], you are supposed t ...
- PAT乙级 1003 我要通过! (20分)
PAT乙级练习总结 PAT乙级 1003 我要通过! (20分) 第二版有注释,希望我的思路可以帮助你. 文章目录 PAT乙级练习总结 一.1003题目 二.第一版只过了三个点 三.第二版 1003 ...
最新文章
- SnackbarUtilDemo【Snackbar的封装类】
- iOS 生成二维码/条形码
- 【敏捷测试】一个测试人员在参与敏捷测试的经验分享(3)
- matlab统计矩阵元素的出现次数
- leetcode笔记:Search in Rotated Sorted Array
- java 命名管道_Java中命名管道的并发读/写(在Windows上)
- 这份1307页Android面试全套真题解析,源码+原理+手写框架
- Webpack实战(四):教教你如何轻松搞定-预处理器(loader)
- GitHub:为什么我们最终选择放弃了 jQuery
- 四大浏览器再战Windows平台:Opera勇夺第一
- redis zset怎么排序_redis(set、zset)类型使用和使用场景
- 二级 c语言真题及答案,3月计算机二级C语言真题及答案(完整版)
- QQ-AR实物识别!香蕉扫一扫,解救小黄人?
- 杰里之混响音效调试【篇】
- 高端制造业企业信息化解决方案,工业电商平台设备、数据、体系预测性维护
- Daydream播放3D视频(视频左右分屏3D效果)
- 6.20thingworx之bug记录
- matlab 蜗杆轮廓,solidworks环面蜗杆画法
- C语言进阶第15式:逻辑运算符分析
- garch dcc用matlab,用matlab工具箱怎么对garch模型做...
热门文章
- java serializable 源码_Java源码分析之-Serializable接口
- C 桥接模式 - 开关和电器
- java fx choicebox_JavaFX:具有图像和文本的ChoiceBox
- 网络营销理论模型_网络营销:课堂笔记(第四章下)
- 本地虚拟机上的docker安装mysql_Linux虚拟机上安装docker,并使用docker安装mysql,tomcat...
- 查询计算机专业及选修了英语的学生,实验五 数据库综合查询(学生)
- stc单片机485发送多出一字节_单片机干货!STC8H案例制作分享(内含高清实物动图)...
- java gnu_GNU/Linux下Java开发环境的安装和配置 | 学步园
- vant按需引入没样式_vue vant-ui样式出不来的问题
- kali使用笔记本自带无线网卡_无线网卡?那是什么?