#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 1000 + 10;
int main(){
int t, count = 1;
cin >> t;
while (t--){
char m[maxn], n[maxn];
cin >> m >> n;
int a[maxn], b[maxn], c[maxn];
int i, j, k,l;
i = strlen(m); j = strlen(n);
int leni = i; int lenj = j;
while (i--){
k = 0;
a[k] = m[i] - '0';
k++;
}
while (j--){
l = 0;
b[l] = n[j] - '0';
l++;
}
int p, x = 0;
for (p = 0; x || p < leni || p < lenj; p++){
if (p < leni) x += a[p];
if (p < lenj) x += b[p];
c[p] = x % 10;
x = x / 10;
}
cout << "Case " << count << ":" << endl;
cout << m << " + " << n << " = ";
while (p--){ cout << c[p-1]; }
cout << endl << endl;
count++;
}
return 0;
}
我试了一下,在循环体内给数组a赋值还是正常的,出了循环体就只有a[0]是对的,其他都乱了,不知道是哪里错了……