PAT Advanced 1065 A+B and C (64bit) (20 分)(关于g++和clang++修改后能使用)
2024-09-05 15:45:18
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
这个上面有2个Case是不能过的,在g++,但是在clang++可以过。
#include <iostream>
using namespace std;
int main(){
/**
依据算法笔记,以及其他人的博客,可知
可以进行溢出判断
1.即两个正数和为负数,溢出,比结果大
2.两个负数和为正数,溢出,比结果肯定小
3.一正一负直接比较
long long长度[-2**63,2**63)
*/
int T;long long a,b,c;
cin>>T;bool flag;//flag为true是true,false为false
for(int i=;i<T;i++){
cin>>a>>b>>c;
if(a>&&b>&&(a+b)<) flag=true;
else if(a<&&b<&&(a+b)>=) flag=false;
else{
if(a+b>c) flag=true;
else flag=false;
}
if(flag) cout<<"Case #"<<(i+)<<": true"<<endl;
else cout<<"Case #"<<(i+)<<": false"<<endl;
}
system("pause");
return ;
}
要想在g++过这个Case 可以使用用res存储的方式。至今不知道为啥不能直接比较,在g++上
#include <iostream>
using namespace std;
int main(){
/**
依据算法笔记,以及其他人的博客,可知
可以进行溢出判断
1.即两个正数和为负数,溢出,比结果大
2.两个负数和为正数,溢出,比结果肯定小
3.一正一负直接比较
long long长度[-2**63,2**63)
*/
int T;long long a,b,c,res;
cin>>T;bool flag;//flag为true是true,false为false
for(int i=;i<T;i++){
cin>>a>>b>>c;
res=a+b;
if(a>&&b>&&res<) flag=true;
else if(a<&&b<&&res>=) flag=false;
else{
if(res>c) flag=true;
else flag=false;
}
if(flag) cout<<"Case #"<<(i+)<<": true"<<endl;
else cout<<"Case #"<<(i+)<<": false"<<endl;
}
system("pause");
return ;
}
最新文章
- Hui之Hui.js 官方文档
- 【小白的CFD之旅】12 敲门实例【续2】
- 修改centos启动项
- Android Paint和Color类绘画实例
- Windows下Python工具pip的安装
- C#出题库项目的总结(1)
- TBluetoothLE
- 通过软引用和弱引用提升JVM内存使用性能的方法(面试时找机会说出,一定能提升成功率)
- 河北大学python选修课00次作业
- js中style,currentStyle和getComputedStyle的区别以及获取css样式操作方法
- Sqlserver脚本创建登录名密码
- OpenCV3 for python3 学习笔记1
- javascript 新建实例对象
- Synchronzied(内置锁)
- 课程一(Neural Networks and Deep Learning),第一周(Introduction to Deep Learning)—— 0、学习目标
- 自己动手写Impala UDF
- [Forward]Sweeping the IDisposable minefield
- day 56 linux的安装python3 ,虚拟环境,mysql ,redis
- go 函数举例练习
- Android 如何修改默认输入法
热门文章
- ENGINE =MyISAM DEFAULT CHARACTER SET latin1 COLLATE latin1_general_cs AUTO_INCREMENT=0; 什么意思
- 看完你也想编写自己的 react 插件
- List of Mozilla-Based Applications
- 网络协议之TCP/IP协议
- C++ 左值与右值
- WPF中的WndProc
- NumericStream &;&; Stream综合练习
- Redis存储对象序列化和反序列化
- Matlab——矩阵运算 矩阵基本变换操作
- 获取当前页面的title