1065 A+B and C (64bit) (20 分)
 

Given three integers A, B and C in [−], 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 (≤). 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的大小为[-2^63, 2^63],用long long 存储A和B的值,以及他们相加的值sum:
如果A > 0, B < 0 或者 A < 0, B > 0,sum是不可能溢出的
如果A > 0, B > 0,sum可能会溢出,sum范围理应为(0, 2^64 – 2],溢出得到的结果应该是[-2^63, -2]是个负数,所以sum < 0时候说明溢出了

如果A < 0, B < 0,sum可能会溢出,同理,sum溢出后结果是大于0的,所以sum > 0 说明溢出了

AC代码:

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
long long a,b,c,sum;
int main(){
int n;
cin>>n;
for(int i=;i<=n;i++){
cin>>a>>b>>c;
sum=a+b;
if(a>&&b>&&sum<=){
cout<<"Case #"<<i<<": "<<"true"<<endl;
}else if(a< &&b< &&sum>=){
cout<<"Case #"<<i<<": "<<"false"<<endl;
}else if(sum>c){
cout<<"Case #"<<i<<": "<<"true"<<endl;
}else{
cout<<"Case #"<<i<<": "<<"false"<<endl;
}
}
return ;
}

PAT 甲级 1065 A+B and C (64bit) (20 分)(溢出判断)*的更多相关文章

  1. 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 ...

  2. PAT 甲级 1065. A+B and C (64bit) (20) 【大数加法】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1065 思路 因为 a 和 b 都是 在 long long 范围内的 但是 a + b 可能会 ...

  3. PAT Advanced 1065 A+B and C (64bit) (20 分)(关于g++和clang++修改后能使用)

    Given three integers A, B and C in [−], you are supposed to tell whether A+B>C. Input Specificati ...

  4. PAT甲级:1124 Raffle for Weibo Followers (20分)

    PAT甲级:1124 Raffle for Weibo Followers (20分) 题干 John got a full mark on PAT. He was so happy that he ...

  5. PAT甲级——1065 A+B and C (64bit)

    1065 A+B and C (64bit) Given three integers A, B and C in [−2​63​​,2​63​​], you are supposed to tell ...

  6. 【PAT甲级】1065 A+B and C (64bit) (20 分)(大数溢出)

    题意: 输入三个整数A,B,C(long long范围内),输出是否A+B>C. trick: 测试点2包括溢出的数据,判断一下是否溢出即可. AAAAAccepted code: #defin ...

  7. PAT A 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. Inpu ...

  8. PAT甲题题解-1065. A+B and C (64bit) (20)-大数溢出

    第一眼以为是大数据,想套个大数据模板,后来发现不需要.因为A.B.C的大小为[-2^63, 2^63],用long long 存储他们的值和sum. 接下来就是分类讨论:如果A > 0, B & ...

  9. PAT 甲级 1116. Come on! Let's C (20) 【循环判断】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1116 思路 注意一个细节 如果没有本来 ID 的 后来又查了这个ID 不是输出 checked ...

随机推荐

  1. pt100、pt1000,和热电偶

    最近温度测试这块,已使用过pt100.pt1000,和热电偶,这里进行大致的总结.1.pt系列pt100和pt1000的精度相比较,1000更加精细,毕竟他的电阻值更加大.两个电阻都是有分度表的,pt ...

  2. Linux 之 光标消失隐藏术

    下面是 Linux 光标突然不见的解决办法: 直接敲命令行就行 echo -e "\033[?25l"  隐藏光标 echo -e "\033[?25h" 显示 ...

  3. js原型和原型链的问题

    <script> //js原型和原型链的概念 functionperson(name){ this.name=name; } person.prototype.age=18; person ...

  4. 洛谷 P1854 花店橱窗布置 题解

    Analysis 给定一个f*v的矩阵 要求从第一行走到第f行,每行取走一个数, 且该行所取的数必须必上一行所取的数的列数大 , 求所能取走的最大值 注意每一行所取走的数字的列数必须大于等该行的行号 ...

  5. Oracle 异步IO 优缺点

    一.Oracle在Linux下使用异步IO配置 最近在测试Oracle的时候,很想测试下使用异步IO的性能.但是异步IO是需要专门配置的,否则的话,容易遇到很著名的“ORA-01578: ORACLE ...

  6. 记下mongoose(转载)

    连接mongodb时使用的是mongoose模块,安装和使用方法如下: 安装: npm install mongoose --save 使用: let mongoose = require('mong ...

  7. leetcode解题报告(24):Pascal's TriangleII

    描述 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [ ...

  8. GSS1 A - Can you answer these queries I

    //题意:询问一段区间的最大子序列的值. //做法:维护四个值:包含当前区间左端点的最大子区间LM,包含当前区间右端点的最大子区间RM.当前区间的最大子区间M, 当前区间的区间和S //tree[ro ...

  9. (25)打鸡儿教你Vue.js

    vue-cli // 全局安装 vue-cli npm install --global vue-cli // 创建一个基于 webpack 模板的新项目 vue init webpack my-pr ...

  10. vue日常学习(2)

    1.组件学习之内容分发 1.1 作用域插槽 父级 <div class="parent"> <child> <template scope=" ...