AC代码
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
char a[1000],b[1000];
int a_int[1001],b_int[1001];
int a_len,b_len,max_len;
int n;
cin >> n;
for(int j = 1; j <= n; j++ ) {
memset(a_int, 0, sizeof(a_int));
memset(b_int, 0, sizeof(b_int));
cin >> a >> b;
a_len = strlen(a);
b_len = strlen(b);
for (int i = a_len - 1; i >= 0; i--) {
a_int[a_len - 1 - i] = a[i] - '0';
}
for (int i = b_len - 1; i >= 0; i--) {
b_int[b_len - 1 - i] = b[i] - '0';
}
max_len = a_len > b_len ? a_len : b_len;
for (int i = a_len; i < max_len; i++){
a_int[i] = 0;
}
for (int i = b_len; i < max_len; i++){
b_int[i] = 0;
}
int carryBit = 0;
for (int i = 0; i <= max_len; i++) {
a_int[i] = a_int[i] + b_int[i] + carryBit;
if (a_int[i] >= 10) {
a_int[i] = a_int[i] - 10;
carryBit = 1;
} else {
carryBit = 0;
}
}
cout<<"Case "<<j<<":"<<endl;
cout<<a<<" "<<"+"<<" "<<b<<" "<<"="<<" ";
if (a_int[max_len] != 0) cout << 1;
for (int i = max_len - 1; i >= 0; i--) {
cout << a_int[i];
}
if (j != n) {
cout << endl << endl;
} else {
cout << endl;
}
}
system("PAUSE");
return 0;
}