Python实现Pat 1065. A+B and C (64bit) (20)
来源:互联网 发布:致真大厦 中电数据服务 编辑:程序博客网 时间:2024/06/15 10:42
题目描述
Given three integers A, B and C in [-263, 263), you are supposed to tell whether A+B > C.
输入描述:
The first line of the input gives the positive number of test cases, T (<=1000). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.
输出描述:
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).
输入例子:
3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0
输出例子:
Case #1: false
Case #2: true
Case #3: false
解答
用C或c++语言实现起来比较麻烦,要考虑溢出问题:(参考的博客)
1.long long 取值为【-2^63, 2^63)左开右闭。
2.超出范围的时候要判断溢出情况,考虑溢出后的取值
3.A+B的值必须用long long 类型 的res存储后才能与C进行比较,不能直接放到if()中进行比较不然测试点2、3过不去。
4.分情况判断时候要用else if 不能一串if,不然可能会出现一种情况满足几个条件,造成后面的flag覆盖前面的(正负溢出应该优先判断)
而用Python就非常简单了。而且也能通过测试。
n=int(input())for i in range(n): abc=[int(x) for x in input().split(' ')] if abc[0]+abc[1]>abc[2]: print("Case #%d: true"%(i+1)) else: print("Case #%d: false" % (i+1))
- Python实现Pat 1065. A+B and C (64bit) (20)
- PAT A 1065. A+B and C (64bit) (20)
- PAT-A 1065. A+B and C (64bit) (20)
- PAT-A-1065. A+B and C (64bit) (20)
- 【PAT】1065. A+B and C (64bit) (20)
- 浙大PAT 1065. A+B and C (64bit) (20)
- PAT 1065. A+B and C (64bit) (20)
- PAT 1065. A+B and C (64bit) (20)
- ZJU-PAT 1065. A+B and C (64bit) (20)
- PAT 1065. A+B and C (64bit) (20)
- PAT 1065. A+B and C (64bit) (20)
- PAT 1065. A+B and C (64bit) (20)
- PAT:1065. A+B and C (64bit) (20)
- PAT甲级.1065. A+B and C (64bit) (20)
- PAT 1065. A+B and C (64bit) (20)
- 1065. A+B and C (64bit) (20) PAT 甲级
- 【PAT甲级】1065. A+B and C (64bit) (20)
- PAT甲级1065. A+B and C (64bit) (20)
- JavaScript 面向对象之 原型-prototype
- java详解 --- 随机数、函数及数组部分
- JPA
- Java知识点与BUG的汇总(个人整理的)以及一些代码优化的方法、项目结构剖析的描述
- java基础 3、"=="和equals方法有什么区别
- Python实现Pat 1065. A+B and C (64bit) (20)
- 权限学习 -- Spring Security数据库、缓存、自定义决策
- 11月工作总结
- 一致性检验 -- Kappa 系数
- matlab---之max函数的使用方法
- Android自定义view画五星红旗
- Linux常用命令
- java基础 4、静态变量和实例变量的区别
- 数据库基础语法(上)