【来源】
【分析】
本题看似简单,需要注意数据的范围为[-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;
}