PAT class B 1073 problem solving

Title details:

Common scoring method for 1073 multiple choice questions (20 points)
Correcting multiple-choice questions is a troublesome thing. There are many different scoring methods. One of the most common scoring methods is: if the examinee selects some correct options and does not select any wrong options, he will get a 50% score; If a candidate chooses any of the wrong options, he cannot score. For this question, please write a program to help the teacher correct multiple-choice questions, and point out which question has the most wrong choice.

Input format:
Input two positive integers N (≤ 1000) and M (≤ 100) are given in the first line, which are the number of students and the number of multiple topics respectively. Then, in line M, the full score (positive integer not exceeding 5), the number of options (positive integer not less than 2 and not more than 5), the number of correct options (positive integer not exceeding the number of options) and all correct options are given in sequence in each line. Note that the options of each question are arranged in order starting from the English letter A. Each item is separated by a space. In the last N lines, each line gives a student's answer, and the answer format of each question is (number of options selected, option 1...), which is given in the order of questions. Note: the questions ensure that the students' answers are legal, that is, there is no case that the number of selected options exceeds the actual number of options.

Output format:
The scores of each student are given in the order of input. Each score occupies one line and outputs one decimal place. Finally, output the information of the topic option with the most errors in the format of: number of errors, topic number (topics are numbered from 1 in the order of input) - option number. If there is juxtaposition, one option for each line will be output in the ascending order of topic number; If they are juxtaposed again, they will be output in the order of increasing the option number. There must be no extra spaces at the beginning and end of the line. If no one is wrong with all the questions, it will output Too simple on the last line.

Input sample:

3 4 
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (3 b d e) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (1 c) (4 a b c d)

Output example:

3.5
6.0
2.5
2 2-e
2 3-a
2 3-b

answer:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_set>

using namespace std;

const int N = 1010, M = 110;

struct prob {
    double sc;
    int cnt, rt;
    unordered_set<char> h;
} p[M];

int n, m;
double res[N];
int wa[M][5];

int main() {
    cin >> n >> m;
    for (int i = 1; i <= m; i ++) {
        cin >> p[i].sc >> p[i].cnt >> p[i].rt;
        for (int j = 0; j < p[i].rt; j ++) {
            char c; cin >> c;
            p[i].h.insert(c);
        }
    }
    getchar();
    for (int i = 1; i <= n; i ++) {
        string t; getline(cin, t);
        for (int j = 0, kk = 1; j < t.size(); j ++) {
            if (isdigit(t[j])) {
                int a = t[j] - '0';
                int flag = 0;
                bool st[5] = {0};
                for (int k = 1; k <= 2 * a; k ++) {
                    if (t[j + k] != ' ') {
                        st[t[j + k] - 'a'] = true;
                        if (!p[kk].h.count(t[j + k])) 
                            flag = 1, wa[kk][t[j + k] - 'a'] ++;
                    }
                }
                for (auto& x : p[kk].h) {
                   if (!st[x - 'a']) wa[kk][x - 'a'] ++;
                }
                if (!flag) {
                    if (a < p[kk].rt) res[i] += p[kk].sc / 2;
                    else res[i] += p[kk].sc;
                }
                kk ++;
            }
        }
    }
    for (int i = 1; i <= n; i ++) printf("%.1lf\n", res[i]);
    int ans = 0;
    for (int i = 1; i <= m; i ++) {
        for (int j = 0; j < 5; j ++) {
            ans = max(ans, wa[i][j]);
        }
    }
    if (!ans) printf("Too simple");
    else {
        for (int i = 1; i <= m; i ++) {
            for (int j = 0; j < 5; j ++) {
                if (wa[i][j] == ans)
                    printf("%d %d-%c\n", wa[i][j], i, j + 'a');
            }
        }
    }
    return 0;
}

Keywords: C C++ Algorithm

Added by aneesme on Mon, 07 Feb 2022 12:28:24 +0200