PAT-PAT (Advanced Level) Practise A+B and C (64bit) (20) 【二星级】
2015-11-19 22:12
393 查看
题目链接:http://www.patest.cn/contests/pat-a-practise/1065
题面:
时间限制
100 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
HOU, Qiming
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:
Sample Output:
题目大意:
判断A+B是否大于C。
解题:
因为直接计算会爆long long,先减再加也不行,那么就取除10部分计算,模10部分分别计算。最后把结果整理一下判断即可。
代码:
题面:
1065. A+B and C (64bit) (20)
时间限制100 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
HOU, Qiming
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
题目大意:
判断A+B是否大于C。
解题:
因为直接计算会爆long long,先减再加也不行,那么就取除10部分计算,模10部分分别计算。最后把结果整理一下判断即可。
代码:
#include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <cstring> using namespace std; #define LL long long int main() { int n; LL a,ab1,ab2,b,c,c1,c2,t1,t2; cin>>n; for(int i=1;i<=n;i++) { cout<<"Case #"<<i<<": "; cin>>a>>b>>c; ab1=a/10+b/10; ab2=a%10+b%10; c1=c/10; c2=c%10; t1=ab1-c1; t2=ab2-c2; t1+=(t2/10); t2%=10; if(t2<0) t2+=10,t1-=1; if(t1<0||(t1==0&&t2==0))cout<<"false\n"; else cout<<"true\n"; } return 0; }
相关文章推荐
- 每天一点matlab——如何将一幅图像(640*360)分成4个局域(160*90)读取
- 通过管道进行线程间通信:字节流。字符流的用法及API类似
- 【iOS学习笔记】iOS算法(五)之折半查找
- 【iOS学习笔记】iOS算法(四)之冒泡排序
- IIS7.0上传文件限制的解决方法
- Linux目录规范和含义(转)
- 12.值动画、测量规则
- 代码手写UI,xib和StoryBoard间的博弈,以及Interface Builder的一些小技巧
- 图像的空间转换 HSI→RGB 和 RGB→HSI
- Activity生命周期详解
- OpenGL ES 模型视图操作入门
- UltraEdit 激活 破解 教程
- SRM 670 div2 B BearSlowlySorts
- 史话未完待续。。。
- 【iOS学习笔记】iOS算法(三)之插入排序
- Java 调用 C++ (Java 调用 dll)康哥手把手教你
- python+pyqt5
- Hibernate Tools安装与使用
- Lowest Common Ancestor in a Binary Tree
- .NET跨平台之旅:升级至ASP.NET 5 RC1,Linux上访问SQL Server数据库