编程语言
首页 > 编程语言> > PTA 乙级 1058 选择题 (20分) C++

PTA 乙级 1058 选择题 (20分) C++

作者:互联网

 

 

 题目输入和输出比较繁琐,说一下思路

思路:

 1 #include<iostream>
 2 #include<vector>
 3 #include<cstring>
 4 
 5 using namespace std;
 6 
 7 struct text {
 8     /*满分*/
 9     int full;
10     /*选项个数*/
11     int num;
12     /*正确选项个数*/
13     int right;
14     /*正确选项字母*/
15     char word[5];
16 };
17 
18 int main() {
19     /*N,M*/
20     int n = 0, m = 0;
21     cin >> n >> m;
22     /*题目*/
23     vector<text> topic(m);
24     /*学生得分*/
25     vector<int> stur(n);
26     /*每个题错的次数*/
27     vector<int> wrong(m);
28     //有关题目信息的输入
29     for (int i = 0; i < m; ++i) {
30         cin >> topic[i].full >> topic[i].num >> topic[i].right;
31         for (int j = 0; j < topic[i].right; ++j)cin >> topic[i].word[j];
32     }
33     for (int i = 0; i < n; ++i) {
34         for (int j = 0; j < m; ++j) {
35             int r = 0;                                    //学生选中选项个数
36             char w[5] = { '\0' }, c;                    //注意在topic的结构体中,char word[5]默认初始化为'\0',保持空位一致
37             while ((c = getchar()) != ')') {            //在1052卖个萌中用到过这种输入方法,实现按规定格式的输入
38                 if (c == '(') {
39                     cin >> r;
40                     for (int k = 0; k < r; ++k)cin >> w[k];
41                 }
42             }
43             if (r == topic[j].right && strcmp(topic[j].word, w) == 0) stur[i] += topic[j].full;    //正确
44             else wrong[j]++;                                                                    //错误,即题错误次数增加
45         }
46     }
47     int max = wrong[0];
48     for (int i = 0; i < m; ++i) if (max < wrong[i]) max = wrong[i];        //统计最高错误次数
49     for (int i = 0; i < n; ++i)cout << stur[i] << endl;
50     if (max != 0) {
51         cout << max;
52         for (int i = 0; i < m; ++i) if (wrong[i] == max) cout << ' ' << i + 1;    //输出和最高错误次数相同的题目编号
53     }
54     else cout << "Too simple";
55     return 0;
56 }

 

 

标签:选项,20,错误,1058,++,C++,cin,topic,int
来源: https://www.cnblogs.com/SCP-514/p/13567760.html