方法1
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main ( ) {
int n;
cin>> n;
string a, b, c;
int s1[ 12 ] , s2[ 12 ] ;
int t = 1 ;
while ( t<= n) {
cin>> a>> b>> c;
memset ( s1, 0 , sizeof ( s1) ) ;
memset ( s2, 0 , sizeof ( s2) ) ;
int neg = 1 ;
for ( int i = 12 - a. length ( ) ; i< 12 ; i++ ) {
if ( a[ i- ( 12 - a. length ( ) ) ] == '-' ) {
neg = - 1 ;
} else {
s1[ i] = neg* ( a[ i- ( 12 - a. length ( ) ) ] - '0' ) ;
}
}
neg = 1 ;
for ( int i = 12 - b. length ( ) ; i< 12 ; i++ ) {
if ( b[ i- ( 12 - b. length ( ) ) ] == '-' ) {
neg = - 1 ;
}
else {
s1[ i] + = neg* ( b[ i- ( 12 - b. length ( ) ) ] - '0' ) ;
if ( abs ( s1[ i] ) >= 10 ) {
s1[ i] = s1[ i] % 10 ;
s1[ i- 1 ] + = neg;
}
}
}
neg = 1 ;
for ( int i = 12 - c. length ( ) ; i< 12 ; i++ ) {
if ( c[ i- ( 12 - c. length ( ) ) ] == '-' ) {
neg = - 1 ;
}
else {
s2[ i] = neg* ( c[ i- ( 12 - c. length ( ) ) ] - '0' ) ;
}
}
bool flag = false ;
for ( int i = 0 ; i< 12 ; i++ ) {
if ( s1[ i] > s2[ i] ) {
flag = true ;
break ;
}
if ( s1[ i] < s2[ i] ) {
flag = false ;
break ;
}
}
if ( flag) {
cout<< "Case #" << t<< ": true\n" ;
}
else {
cout<< "Case #" << t<< ": false\n" ;
}
t++ ;
}
return 0 ;
}
方法2
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main ( ) {
int n;
cin>> n;
long long int a, b, c;
int t = 1 ;
while ( n-- ) {
cin>> a>> b>> c;
if ( a+ b> c) {
cout<< "Case #" << t<< ": true\n" ;
}
else {
cout<< "Case #" << t<< ": false\n" ;
}
t++ ;
}
return 0 ;
}