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 supposed to tell whether A+B>C.
输入格式:
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).
.
输出格式:
For each test case, print your results in M lines, each contains the shortest distance between the corresponding given pair of exits.
输入样例:
3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0
输出样例:
Case #1: false
Case #2: true
Case #3: false
题意:判断a+b是否大于c,需要注意的是a,b,c的范围为 [−2^63, 2^63],即便在使用long long的情况下仍会可能出现溢出。
思路:所以判断要分为以下4种情况讨论,if(a>0&&b>0&&sum<0) flag = true;
else if(a<0&&b<0&&sum>=0) flag = false;
else if(sum>c) flag = true;
else flag = false;
总之,注意类型的范围就可,本题不难。
附数据类型的范围:
整型:
byte:-2^7 ~ 2^7-1,即-128 ~ 127。1字节。Byte。末尾加B
short:-2^15 ~ 2^15-1,即-32768 ~ 32767。2字节。Short。末尾加S
有符号int:-2^31 ~ 2^31-1,即-2147483648 ~ 2147483647。4字节。Integer。
无符号int:0~2^32-1。
long:-2^63 ~ 2^63-1,即-9223372036854774808 ~ 9223372036854774807。8字节。Long。末尾加L。(也可以不加L)
浮点型:
float:4字节。Float。末尾加F。(也可以不加F)
double:8字节。Double。
字符型:
char:2字节。Character。
布尔型:
boolean:Boolean。
代码:
#include <cstdio>
using namespace std;
int main(){int t;scanf("%d",&t);long long a,b,c; for(int i=1;i<=t;i++){scanf("%lld %lld %lld",&a,&b,&c);long long sum=a+b;bool flag;if(a>0&&b>0&&sum<0) flag = true;else if(a<0&&b<0&&sum>=0) flag = false;else if(sum>c) flag = true;else flag = false;if(flag == true){printf("Case #%d: true\n",i);}else {printf("Case #%d: false\n",i);}}return 0;
}
参考文献:csdn、8种基本数据类型及取值范围、https://blog.csdn.net/qq_25800311/article/details/82945852
GOGOGOGO!
Love Joyee forever!
PATA 1065 A+B and C (64bit) (20分)相关推荐
- 1065 A+B and C (64bit) (20 分)【难度: 简单 / 思维 高精度】
https://pintia.cn/problem-sets/994805342720868352/problems/994805406352654336 方法一: 用高精度的板子写一下是可以的,不过 ...
- 【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 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 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)
1065 A+B and C (64bit) (20分) Given three integers A, B and C in [−263,263], you are supposed t ...
- 7-1 查找书籍(20 分)(程序设计天梯赛模拟练习题)
7-1 查找书籍(20 分) 给定n本书的名称和定价,本题要求编写程序,查找并输出其中定价最高和最低的书的名称和定价. 输入格式: 输入第一行给出正整数n(<10),随后给出n本书的信息.每本书 ...
- PTA—输出全排列 (20分) 递归回溯思想
PTA-输出全排列 (20分) 递归回溯思想 题目要求: 请编写程序输出前n个正整数的全排列(n<10),并通过9个测试用例(即n从1到9)观察n逐步增大时程序的运行时间. 输入格式: 输入给出 ...
最新文章
- 有原型的对象和没有原型的对象
- python壁纸程序代码_python设置windows桌面壁纸的实现代码
- java程序的运行结果依赖操作系统吗_java模拟试卷及答案及解析4
- UILable的text设置中划线(删除线)
- hprose出现500: Internal Server Error
- 为什么下拉框拉不下来_零线不带电,为什么还要拉一条?直接用地做零线不是更省钱?...
- 9/100. Reverse Linked List
- java 范围搜寻要怎么弄_搜索范围
- iOS 两个tableview的 瀑布流
- java面试-JVM调优和参数配置
- HTTP的padding状态
- 基于R语言、MATLAB、Python机器学习方法与案例分析
- 细说php完美分页类
- Julia安装与配置Jupyter Notebook
- 美团 2021 届秋季校园招聘—小团的 AB 队(排序)
- scratch的官方版本和其他的改编版本/小喵科技Kittenblock/snap!/TurboWarp
- 9367: 【动态规划】雷涛的小猫
- TestLink汉化操作
- 递归_青蛙跳台阶(进阶版)
- Windows battery report