PAT Level B-Multiple Choice Questions

Topic description
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
Input two positive integers N and M on the first line, which are the number of students and the number of multiple-choice questions, respectively.
Then M lines, each line gives one question in sequence 满分值 选项个数 正确选项个数 所有正确选项.
In the last N lines, each line gives a student's answer, and the format of each answer is 选中的选项个数 选项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 score of each student is given in the order of input, and each score occupies one line.
The last line of the output error the most topics 错误次数and 编号(Subject numbered starting from 1 in the order of input).

  • If there are parallels, they will be output in increasing order of 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.

Note that when judging a question, only if you choose all the correct ones can you get the score for the question.

Input example
3 4
3 4 2 ac
2 5 1 b
5 3 2 bc
1 5 4 abde
(2 ac) (2 bd) (2 ac) (3 abe)
(2 ac) (1 b) (2 ab) ( 4 abde)
(2 bd) (1 e) (2 bc) (4 abcd)

Sample output
3
6
5
2 2 3 4

Data range
N ≤ 1000, M ≤ 100


answer:

解题思路: Difficulty of the problem lies 读入with 如何将学生的答案与标准答案进行匹配;

  1. 读入: You can read in first (, then process the middle 学生的答案, and finally read in );
  2. 匹配: If 学生的答案and 标准答案, respectively a b c, a b c das long as it is converted abc, abcdand finally
#include <iostream>
using namespace std;

const int N = 1010, M = 110;

int stu[N];
string answer[M];
int wrong[M], score[M];

int main()
{
    
    
	int n, m;
	cin >> n >> m;
	
	for (int i = 1; i <= m; i ++)
	{
    
    
		int total, True;
		cin >> score[i] >> total >> True;
		string s;
		while(True --)
		{
    
    
			char x;
			cin >> x;
			s += x;
		}
		answer[i] = s;
	}
	
	for (int i = 1; i <= n; i ++)
		for (int j = 1; j <= m; j ++)
		{
    
    
		    char left;
		    cin >> left;
			int submit;
			cin >> submit;
			string s;
			while(submit --)
			{
    
    
			    char x;
				cin >> x;
				s += x;
			}
			char right;
			cin >> right;
			if(answer[j] == s) stu[i] += score[j];
			else wrong[j] ++; 
		}
		
	for (int i = 1; i <= n; i ++) cout << stu[i] << endl;
	
	int maxv = 0;
	for (int i = 1; i <= m; i ++)
		if(wrong[i] > maxv)	maxv = wrong[i];

	if(!maxv) cout << "Too simple" << endl;	
	else
	{
    
    
	    cout << maxv;	
	    for (int i = 1; i <= m; i ++)
		    if(wrong[i] == maxv) cout << ' ' << i;
	}
	
	return 0;	
}

Guess you like

Origin blog.csdn.net/weixin_46239370/article/details/113879945