struct应用_1058 选择题 (20 分)

Posted tornado549

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了struct应用_1058 选择题 (20 分)相关的知识,希望对你有一定的参考价值。

参考: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 }

 

以上是关于struct应用_1058 选择题 (20 分)的主要内容,如果未能解决你的问题,请参考以下文章

P1058 选择题

1058 选择题

1058 A+B in Hogwarts (20 分)

1058 A+B in Hogwarts (20分)

pat 1058 A+B in Hogwarts(20 分)

PAT 甲级 1058 A+B in Hogwarts (20 分) (简单题)