参考:https://www.jianshu.com/p/e6a55efdd239
题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805270356541440
独立出读取答案和作答的函数,利用struct简化程序
1 #include<iostream> 2 using namespace std; 3 4 struct 5 { 6 int score; 7 int answer; 8 int wrong; 9 } probs[100]; 10 11 int readanswer() 12 { 13 char c; 14 int cnt, answer = 0; 15 cin >> cnt; 16 while(cnt--) 17 { 18 while((c=getchar()) == ' '); 19 answer |= (1 << (c - 'a')); 20 } 21 return answer; 22 } 23 24 int main() 25 { 26 int N, M, max_wrong_time=0, useless; 27 cin >> N >> M; 28 for(int i = 0; i < M; i++) 29 { 30 cin >> probs[i].score >> useless; 31 probs[i].wrong = 0; 32 probs[i].answer = readanswer(); 33 } 34 35 for(int i = 0; i < N; i++) 36 { 37 int score = 0; 38 for(int j = 0; j < M; j++) 39 { 40 while(getchar() != '('); 41 if(readanswer() == probs[j].answer) 42 score += probs[j].score; 43 else if(max_wrong_time < ++probs[j].wrong) 44 max_wrong_time = probs[j].wrong; 45 while(getchar() != ')'); 46 } 47 cout << score << endl; 48 } 49 50 if(max_wrong_time == 0) 51 cout << "Too simple"; 52 else 53 { 54 cout << max_wrong_time; 55 for(int i = 0; i < M; i++) 56 if(probs[i].wrong == max_wrong_time) 57 cout << " " << i+1; 58 } 59 return 0; 60 }