1 #include <iostream> 2 #include <string> 3 #include <string.h> 4 using namespace std; 5 6 int main() 7 { 8 int N = 400; 9 //input用来存储输入数据 10 int input[N][N]; 11 memset(input, 0, sizeof(input)); 12 string s; 13 int num = 0; 14 //将接收的string类型转化成数组,便于处理 15 while (cin >> s) 16 { 17 if (s == "0") 18 break; 19 else 20 { 21 for (int i = s.size(), j = N-1; i > 0; i--, j--) 22 { 23 input[num][j] = s[i-1] - 48; 24 } 25 } 26 num++; 27 } 28 29 //sum数组用来处理求和 30 int sum[N]; 31 memset(sum, 0, sizeof(sum)); 32 for (int i = 0; i < N; i++) 33 { 34 for (int j = 0; j < N; j++) 35 { 36 sum[i] += input[j][i]; 37 } 38 } 39 40 for (int i = N-1; i >=0; i--) 41 { 42 sum[i-1] += sum[i]/10; 43 sum[i] = sum[i]%10; 44 } 45 46 int high = 0; 47 for (int i = 0; i < N; i++) 48 { 49 if (sum[i] != 0) 50 { 51 high = i; 52 break; 53 } 54 } 55 56 for (int j = high; j < N; j++) 57 { 58 cout << sum[j]; 59 } 60 cout << endl; 61 62 return 0; 63 }
时间: 2024-10-17 12:55:25