要输入字符串,longlongint不够
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 0Sample Output:
Case #1: false Case #2: true Case #3: false
#include <iostream>#include <math.h>#include <string>#define INF 10000000using namespace std;long long int ahigh=0, alow = 0, bhigh = 0, blow = 0, chigh = 0, clow = 0;bool Cmp(void) {if (ahigh + bhigh > chigh)return true;else if (ahigh + bhigh < chigh)return false;else {if (alow + blow > clow)return true;elsereturn false;}}int main(void) {int n;cin >> n;for (int i = 0; i < n; i++) {string a, b, c;cin >> a >> b >> c;ahigh = 0;bhigh = 0;chigh = 0;alow = 0;blow = 0;clow = 0;if (a.length() > 9) {for (int j = 0; j < a.length() - 9; j++) {ahigh *= 10;ahigh = ahigh + a[j] - ‘0‘;}for (int j = a.length() - 9; j < a.length(); j++) {alow *= 10;alow = alow + a[j] - ‘0‘;}}else {ahigh = 0;for (int j = 0; j < a.length(); j++) {alow *= 10;alow = alow + a[j] - ‘0‘;}}if (b.length() > 9) {for (int j = 0; j < b.length() - 9; j++) {bhigh *= 10;bhigh = bhigh + b[j] - ‘0‘;}for (int j = b.length() - 9; j < b.length(); j++) {blow *= 10;blow = blow + b[j] - ‘0‘;}}else {bhigh = 0;for (int j = 0; j < b.length(); j++) {blow *= 10;blow = blow + b[j] - ‘0‘;}}if (c.length() > 9) {for (int j = 0; j < c.length() - 9; j++) {chigh *= 10;chigh = chigh + c[j] - ‘0‘;}for (int j = c.length() - 9; j < c.length(); j++) {clow *= 10;clow = clow + c[j] - ‘0‘;}}else {chigh = 0;for (int j = 0; j < c.length(); j++) {clow *= 10;clow = clow + c[j] - ‘0‘;}}if (Cmp())cout << "Case #" << i + 1 << ": true"<<endl;elsecout << "Case #" << i + 1 << ": false"<<endl;}return 0;}
原文:http://www.cnblogs.com/zzandliz/p/5023206.html