1058 Multiple-choice questions (20 marks)

Correcting multiple-choice questions is more troublesome. For this question, please write a program to help the teacher correct multiple-choice questions, and point out which question has the most wrong people.

Input format:

Enter two positive integers N (≤ 1000) and M (≤ 100) in the first line, which are the number of students and the number of multiple-choice questions, respectively. Following M lines, each line gives the full score of a question (a positive integer not exceeding 5), the number of options (a positive integer not less than 2 and not exceeding 5), and the number of correct options (not exceeding the number of options). Number of positive integers), all correct options. Note that the options for each question are arranged in sequence starting from the lowercase English letter a. Each item is separated by 1 space. In the last N lines, each line gives a student’s answer. The answer format of each question is (number of selected options, option 1...), given in the order of the questions. Note: The question guarantees that the student's answer is legal, that is, there is no situation where 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, and each score occupies one line. Note that when judging a question, only if you choose all the correct ones can you get the score for the question . The last line of output wrong most of the topics the number of errors and the number (in order of subject input from the 1numbering starts). If there is a parallel, it will be 递增顺序output according to the number . Separate the numbers with spaces, and there must be no extra spaces at the beginning and end of the line. If all the questions are correct, it will be output on the last line Too simple.

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) (2 b d) (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) (2 b c) (4 a b c d)

Sample output:

3
6
5
2 2 3 4

Ideas:
Insert picture description here

answer:

#include<iostream>
#include<string>

using namespace std;

const int N = 1e4, M = 1e2;
//   每题分数          每题错误总次数   每位学生总分
int fullMark[M], j = 0, wrong[M], student_score[N];
string opt[M];//正确选项个数加正确选项

int main() {
    
    
    ios::sync_with_stdio(false);
	int n, m, temp1;
	cin >> n >> m;
	char temp2;
	for (int i = 0; i < m; i++, j++) {
    
    
		cin >> fullMark[j] >> temp1;
		while ((temp2 = cin.get()) != '\n') {
    
    
			if (temp2 != ' ') opt[j] += temp2;//过滤空格
		}
	}

	string temp3;
	for (int i = 0; i < n; i++) {
    
    
		getline(cin, temp3);
		string temp4 = "";
		int idx = 0;//题下标
		for (int j = 0; j < temp3.length(); j++) {
    
    
			if (temp3[j] == ')') {
    
    
				if (temp4 == opt[idx]) {
    
    
					student_score[i] += fullMark[idx];
				}
				else {
    
    
					wrong[idx]++;
				}
				temp4 = "";
				idx++;
			}
			else if (temp3[j] != ' ' && temp3[j] != '(') temp4 += temp3[j];//过滤空格左右括号
		}
	}

	for (int i = 0; i < n; i++) {
    
    
		cout << student_score[i] << endl;
	}
	int max_wrong = 0;
	for (int i = 0; i < m; i++) {
    
    
		if (max_wrong < wrong[i]) max_wrong = wrong[i];
	}
	if (max_wrong == 0) cout << "Too simple" << endl;
	else {
    
    
		cout << max_wrong;
		for (int i = 0; i < m; i++) {
    
    
			if (max_wrong == wrong[i]) cout << " " << i + 1;
		}
	}

	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44715943/article/details/115052021