1065. A+B and C (64bit) (20)
来源:互联网 发布:数据分析师月薪 编辑:程序博客网 时间:2024/06/12 23:14
1. 原题: https://www.patest.cn/contests/pat-a-practise/1065
2. 思路:
题意:
判断数的大小。
思路:
看到题目的时候,准备用字符串处理了。感觉有点麻烦,看了下其他网友的思路。
原来题目是没有考虑最大边界的。那就简单了。
64位的长整型范围是-2^63~2^63-1,如果考虑最大边界,只有用字符串判断了。
主要是上溢和下溢问题(同号相加才会出现溢出)。a>0, b > 0, 若a+b<0, 说明上溢了。
a<0, b<0, 若a+b>0, 说明下溢了。
判断数的大小。
思路:
看到题目的时候,准备用字符串处理了。感觉有点麻烦,看了下其他网友的思路。
原来题目是没有考虑最大边界的。那就简单了。
64位的长整型范围是-2^63~2^63-1,如果考虑最大边界,只有用字符串判断了。
主要是上溢和下溢问题(同号相加才会出现溢出)。a>0, b > 0, 若a+b<0, 说明上溢了。
a<0, b<0, 若a+b>0, 说明下溢了。
3. 源码(已AC):
#include<iostream>using namespace std;typedef long long int lint;int main(void){//freopen("in.txt", "r", stdin);int N;cin >> N;lint a, b, c;for (int i = 0; i < N; i++){cout << "Case #" << i + 1 << ": ";cin >> a >> b >> c;lint tem = a + b;int flag = 0;if (a > 0 && b > 0 && tem <= 0)//上溢flag = 1;else if (a < 0 && b < 0 && tem >= 0)//下溢flag = 0;else if (tem > c)flag = 1;if (flag == 1)cout << "true\n";elsecout << "false\n";}}
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)
- eclipse下配置GO语言的开发环境
- Mybatis笔记一
- LeetCode 486. Predict the Winner
- OJ提交题目中的语言选项里G++与C++的区别
- 命名管道
- 1065. A+B and C (64bit) (20)
- CSU-1005
- 微信支付集成
- node.js第五天
- jsp request乱码
- 10种使测试人员陷入困境的行为趋势
- 反射相关
- JZOJ 3506. 【NOIP2013模拟11.4A组】善良的精灵
- SQ的工具应用代码