#include<iostream> #include<cctype> #include<cstdlib> #include<cstring> using namespace std; int main(){ char a[110][110]; int result[110]; int num = 0,index; memset(a,‘a‘,sizeof(a)); //没有初始化,wa 了好几次 memset(result,0,sizeof(result)); string s; while(cin >> s){ if(s[0] == ‘0‘) break; index = 0; for(int i = s.length() - 1; i >= 0; i--) //将读入的字符串反转,低位在前 a[num][index++] = s[i]; num++; } int c = 0; for(int i = 0; i < 110; i++){ int sum = 0; for(int j = 0; j < num; j++){ if(isdigit(a[j][i])) sum += a[j][i] - ‘0‘; } sum += c; c = sum / 10; result[i] = sum % 10; } int k; for(k = 109; result[k] == 0; k--); //忽略前导0 for(;k>=0;k--) cout << result[k]; cout << endl; return 0; }
时间: 2024-10-10 20:03:07