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.
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虑溢出的问题。可能是上界。也可能是下界。
能够考虑string模拟大数的方法,代码用了一种适用于两个元素的投机方法。
代码:
#include <iostream>
using namespace std; int main()
{
int n;
cin>>n; long long a,b,c;
int i,j;
for(i=0;i<n;i++) //一种投机取巧的办法。仅适用于两个元素
{
cin>>a>>b>>c;
cout<<"Case #"<<i+1<<": ";
if(a>0&&b>0&&a+b<a&&a+b<b) //上越界,必定大于c
cout<<"true\n";
else if(a<0&&b<0&&a+b>a&&a+b>b) //下越界,必定小于c
cout<<"false\n";
else if(a+b>c) //常规比較
cout<<"true\n";
else
cout<<"false\n";
} return 0;
}
PAT A 1065. A+B and C (64bit) (20)的更多相关文章
- 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 甲级 1065 A+B and C (64bit) (20 分)(溢出判断)*
1065 A+B and C (64bit) (20 分) Given three integers A, B and C in [−], you are supposed to tell whe ...
- PAT 甲级 1065. A+B and C (64bit) (20) 【大数加法】
题目链接 https://www.patest.cn/contests/pat-a-practise/1065 思路 因为 a 和 b 都是 在 long long 范围内的 但是 a + b 可能会 ...
- 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 ...
- 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甲级——1065 A+B and C (64bit)
1065 A+B and C (64bit) Given three integers A, B and C in [−263,263], you are supposed to tell ...
- PAT (Advanced Level) 1065. A+B and C (64bit) (20)
因为会溢出,因此判断条件需要转化.变成b>c-a #include<cstdio> #include<cstring> #include<cmath> #in ...
- PAT甲题题解-1065. A+B and C (64bit) (20)-大数溢出
第一眼以为是大数据,想套个大数据模板,后来发现不需要.因为A.B.C的大小为[-2^63, 2^63],用long long 存储他们的值和sum. 接下来就是分类讨论:如果A > 0, B & ...
- pat(A) 1065. A+B and C (64bit) (java大数)
代码: import java.util.*; import java.math.*; public class Main { public static void main(String args[ ...
随机推荐
- ZOJ1372 POJ 1287 Networking 网络设计 Kruskal算法
题目链接:problemCode=1372">ZOJ1372 POJ 1287 Networking 网络设计 Networking Time Limit: 2 Seconds ...
- Int16 Int32 Int64
数据类型占多大空间 Int16, 等于short, 占2个字节. -32768 32767 Int32, 等于int, 占4个字节. -2147483648 2147483647 Int64, 等于l ...
- 提高你的Java代码质量吧:小心switch带来的空值异常
一.分析 使用枚举定义常量时,会有伴有大量的switch语句判断,目的是为每个枚举解释其行为. 我们知道,目前的Java的switch语句只能判断byte.short.char.int类型(JDK7 ...
- ASP.NET实现图片防盗链(转)
使用httpHandle来实现,对图片文件的请求做专门的处理第一步:创建一个类,继承自IHttpHandler,代码如下 C# code using System; using System.Web; ...
- DWZ在APS.NET WebForm中的使用(一)
1.前言 在最近的项目开发中,使用到了前端框架DWZ.DWZ是一款较为优秀的后台管理界面框架,但官方发布的文档确实令人汗颜,简单几页了事,有点对自己的产品不负责任了.同时感谢网友石头的热心帮助,在我这 ...
- C#事件、委托简单示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- GYP构建系统总结
GYP,Generate Your Project,一个Google开源的构建系统,最开始用于Chromium项目,现在一些其他的开源项目也开始使用GYP,如v8和node-gyp.不管怎样,这仅仅是 ...
- .Net Service部署(二)
1. 以管理员权限运行cmd.exe2. 安装服务 安装服务需要注意的是,如果电脑已经安装了此服务,需要先停止服务然后删除服务, 在进行安装注册,注册前先运行 cd C:\Windows\Micro ...
- jquery学习之笔记一
jquery是继prototype后一个很好用的javascript库.jquery是一个轻量级的库,拥有强大的选择器,出色的DOM操作,可靠的事件处理,完善的兼容性和链式操作等功能. window. ...
- 生成简历经验总结(解析HTML字符串)
在生成简历的过程中,我的做法是首先设计一个word的简历模板,设置好书签,从数据库中读取数据,调用aspose进行填充.一般的数据项包括图片文件都没有问题. 问题出在了HTML字符串上.因为简历中有几 ...