题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392
题解:
1 #include <iostream> 2 #include<cstdio> 3 #include<string> 4 using namespace std; 5 6 int main() { 7 int weigth[] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 }; 8 int n, count = 0; 9 cin >> n; 10 getchar(); 11 string *str = new string[n]; 12 for (int i = 0; i < n; i++) 13 getline(cin, str[i]); 14 for (int i = 0; i < n; i++) { 15 int Sum_weigth = 0; 16 char M; 17 for (int j = 0; j < 17; j++) 18 Sum_weigth = Sum_weigth + (str[i][j] - 48)*weigth[j]; 19 int Z = Sum_weigth % 11; 20 switch (Z) { 21 case 0: 22 M = '1'; break; 23 case 1: 24 M = '0'; break; 25 case 2: 26 M = 'X'; break; 27 case 3: 28 M = '9'; break; 29 case 4: 30 M = '8'; break; 31 case 5: 32 M = '7'; break; 33 case 6: 34 M = '6'; break; 35 case 7: 36 M = '5'; break; 37 case 8: 38 M = '4'; break; 39 case 9: 40 M = '3'; break; 41 default: 42 M = '2'; break; 43 } 44 if (str[i][17] != M) cout << str[i] << endl; 45 else count++; 46 } 47 if (count == n) cout << "All passed"; 48 return 0; 49 }