PAT Basic Level 1011. A+B和C(15)
来源:互联网 发布:全球域名注册量排名 编辑:程序博客网 时间:2024/06/05 08:32
【来源】
1011. A+B和C(15)
【分析】
本题看似简单,需要注意数据的范围为[-231, 231],int类型有可能导致溢出。long long int为64位整数,满足题目要求。
【源码】
#include <iostream>using namespace std;int main(){ int n; cin >> n; for (int i = 0; i < n; ++i){ long long a, b, c; cin >> a >> b >> c; cout << "Case #" << i + 1 << ": "; if (a + b > c){ cout << "true\n"; } else{ cout << "false\n"; } } return 0;}
【扩展】
关于C++中各个数据类型所占的空间大小以及所能表示的数的范围如下图:
生成以上数据的代码(参考了某位大牛的代码):
#include<iostream>#include<string>#include <limits>using namespace std;int main(){ cout << "bool: \t\t" << "Bytes:" << sizeof(bool); cout << "\tMAX:" << (numeric_limits<bool>::max)(); cout << "\t\tMIN:" << (numeric_limits<bool>::min)() << endl; cout << "char: \t\t" << "Bytes:" << sizeof(char); cout << "\tMAX:" << (numeric_limits<char>::max)(); cout << "\t\tMIN:" << (numeric_limits<char>::min)() << endl; cout << "signed char: \t" << "Bytes:" << sizeof(signed char); cout << "\tMAX:" << (numeric_limits<signed char>::max)(); cout << "\t\tMIN:" << (numeric_limits<signed char>::min)() << endl; cout << "unsigned char: \t" << "Bytes:" << sizeof(unsigned char); cout << "\tMAX:" << (numeric_limits<unsigned char>::max)(); cout << "\t\tMIN:" << (numeric_limits<unsigned char>::min)() << endl; cout << "wchar_t: \t" << "Bytes:" << sizeof(wchar_t); cout << "\tMAX:" << (numeric_limits<wchar_t>::max)(); cout << "\t\tMIN:" << (numeric_limits<wchar_t>::min)() << endl; cout << "short: \t\t" << "Bytes:" << sizeof(short); cout << "\tMAX:" << (numeric_limits<short>::max)(); cout << "\t\tMIN:" << (numeric_limits<short>::min)() << endl; cout << "int: \t\t" << "Bytes:" << sizeof(int); cout << "\tMAX:" << (numeric_limits<int>::max)(); cout << "\tMIN:" << (numeric_limits<int>::min)() << endl; cout << "unsigned: \t" << "Bytes:" << sizeof(unsigned); cout << "\tMAX:" << (numeric_limits<unsigned>::max)(); cout << "\tMIN:" << (numeric_limits<unsigned>::min)() << endl; cout << "long: \t\t" << "Bytes:" << sizeof(long); cout << "\tMAX:" << (numeric_limits<long>::max)(); cout << "\tMIN:" << (numeric_limits<long>::min)() << endl; cout << "unsigned long: \t" << "Bytes:" << sizeof(unsigned long); cout << "\tMAX:" << (numeric_limits<unsigned long>::max)(); cout << "\tMIN:" << (numeric_limits<unsigned long>::min)() << endl; cout << "long long: \t" << "Bytes:" << sizeof(long long); cout << "\tMAX:" << (numeric_limits<long long>::max)(); cout << "\tMIN:" << (numeric_limits<long long>::min)() << endl; cout << "double: \t" << "Bytes:" << sizeof(double); cout << "\tMAX:" << (numeric_limits<double>::max)(); cout << "\tMIN:" << (numeric_limits<double>::min)() << endl; cout << "long double: \t" << "Bytes:" << sizeof(long double); cout << "\tMAX:" << (numeric_limits<long double>::max)(); cout << "\tMIN:" << (numeric_limits<long double>::min)() << endl; cout << "float: \t\t" << "Bytes:" << sizeof(float); cout << "\tMAX:" << (numeric_limits<float>::max)(); cout << "\tMIN:" << (numeric_limits<float>::min)() << endl; cout << "size_t: \t" << "Bytes:" << sizeof(size_t); cout << "\tMAX:" << (numeric_limits<size_t>::max)(); cout << "\tMIN:" << (numeric_limits<size_t>::min)() << endl; cout << "string: \t" << "Bytes:" << sizeof(string) << endl; system("pause"); return 0;}
0 0
- PAT Basic Level 1011. A+B和C(15)
- PAT BASIC LEVEL 1011. A+B和C (15)
- PAT(Basic Level):A+B和C
- PAT.Basic Level. A+B和C
- PAT (Basic Level) Practise (中文)1011. A+B和C (15) C语言
- PAT (Basic Level) Practise (中文)1011. A+B和C (15)
- PAT (Basic Level) Practise (中文)1011. A+B和C (15)
- PAT (Basic Level)1011. A+B和C
- Pat(Basic Level)Practice--1011(A+B和C)
- 【C++】浙大PAT (Basic Level)1011. A+B和C (15)
- 【PAT 乙级(Basic Level)】A+B和C
- 【C++】浙大PAT (Basic Level)1016. 部分A+B (15)
- Basic Level 1011. A+B和C (15)
- 1011. A+B和C(PAT Basic)
- PAT(Basic Level)_1011_A+B和C
- PAT乙级(Basic Level)真题 >A+B和C (15)
- PAT BASIC PRACTICE: 1011. A+B和C (15)
- PAT Basic 1011. A+B和C (15)(C语言实现)
- JS正则表达式获取分组内容的方法详解
- 关于static静态变量
- c++ mysql二进制存取,blob存取
- @GeneratedValue 与 @GenericGenerator
- go语言导入文件(固定长解析)(一)
- PAT Basic Level 1011. A+B和C(15)
- super关键字
- infobright优化-group by 字段在过程再次处理会很耗时
- Java关键字介绍之final
- Git修改前一次提交的方法(特别注意保持Change-Id不变)
- poj1703(基于分组)
- RTL Layout Support
- PHP中的Array2String & String2Array
- Seek the Name, Seek the Fame KMP