1065. A+B and C (64bit) (20)
来源:互联网 发布:永宏编程手册 编辑:程序博客网 时间:2024/06/03 13:54
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:31 2 32 3 49223372036854775807 -9223372036854775808 0Sample Output:
Case #1: falseCase #2: trueCase #3: false
此题目的所有数据都在整型范围内,但是如果两数相加后需要进位,就会超出范围。所以此题的关键在于,通过判断每个数的正负,规避加操作。
分为 第一种:a>=0且b>=0
第二种 a>=0&&b<0 或者 a< 0 &&b>=0
第三种 a<0&&b<0
之后每种又分c>=0和c<0两种情况。
#include<iostream>#include<cstdio>using namespace std;int main(){ int n; long long a,b,c; cin>>n; for (int i=0;i<n;i++) { bool flag =true; scanf("%lld %lld %lld",&a,&b,&c); if (a>=0&&b>=0) { if (c>=0) flag=a>c-b; else flag=true; } else if ((a>=0&&b<0)||(b>=0&&a<0)) { flag = a+b>c; } else if (a<0&&b<0) { if (c>=0) flag=false; else flag=a>c-b; } printf("Case #%d: %s\n",i+1,flag?"true":"false"); }}
阅读全文
0 0
- 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)
- 1065. A+B and C (64bit)
- 1065. A+B and C (64bit)
- 1065. A+B and C (64bit)
- 1065.A+B and C (64bit)
- 1065. A+B and C (64bit)
- 1065. A+B and C (64bit)
- 1065. A+B and C (64bit)
- 1065. A+B and C (64bit)
- 1065. A+B and C (64bit)
- 1065. A+B and C (64bit)
- A+B and C (64bit) (20)
- 1065. A+B and C (64bit) (20)
- 【PAT】1065. A+B and C (64bit) (20)
- 1065. A+B and C (64bit) (20)
- 1065. A+B and C (64bit) (20)
- python : trans position cipher
- python3编码转换
- PAT a1127题解
- unity3D学习之声音的采集与处理-audio菜鸟笔记1
- PoEdu_Python_Lesson009_类的基础用法、使用dump写数据到json文件的注意点
- 1065. A+B and C (64bit) (20)
- SVM(Support Vector Machine)分类器详解
- 安卓上裁剪m4a | 铃声是怎么制作出来的
- 1006换个格式输出整数 (15)
- pythonWeb -- Django开发- 模型Model 和 数据库的操作
- 203. Remove Linked List Elements(Java)
- 高级表单与表格、BFC研究
- 自己实现一个简单的散列表
- PoEdu_Python_Lesson010_类的特性