Problem F
Multiple Choice
Mrs. Technoscan often gives multiple choice quizzes in her classroom. She likes this since she is able to feed the forms from the quizzes into a specialized scanner to automatically grade all of the quizzes.
However, this semester, Mrs. Technoscan’s class is being held in a computer lab, and all of the students will have access to a computer during the quizzes. She created a website in which the students can input their multiple choice answers, and has the students’ answers download to a file on her PC.
Help Mrs. Technoscan out by writing this program which reads this file on input, creating a grade for each student based on their answers, and creating sorted results on output.
Input
Input starts with a single integer on it’s own line, $N$ ($1 \le N \le 40$), which indicates the number of questions on the quiz. The next $N$ lines indicate the answer key, each line with the capital letter A, B, C, or D on it.
After reading the answer key, you will read a single integer on its own line, $M$ ($1 \le M \le 300$), which indicates the number of students who took the quiz. Then, for each of the $M$ students comes:
-
A line with an integer $S$ ($1 \le S \le 10^9$) on its own, indicating the student ID of that particular student. You are guaranteed that $S$ will be unique for each student in a particular input.
-
$N$ lines indicating the student’s answers. You are guaranteed each line will only have the capital letter A, B, C, or D on it.
Finally, the last line of input will contain STUDENT_ID_ASC, STUDENT_ID_DESC, GRADE_ASC, or GRADE_DESC, indicating the order in which you should output the results. These values indicate sort by student ID (ascending or descending), or by grade (ascending or descending) respectively. When two or more students have the same number of correct answers, you should order those students by student ID, ascending.
Output
Output the student ID and grade (an integer with the number of correct answers) for each student on its own line, in the order specified by the input.
Sample Input 1 | Sample Output 1 |
---|---|
5 A C D C B 3 1234 A C D C B 4321 A C C B D 800 B D D C D GRADE_DESC |
1234 5 800 2 4321 2 |
Sample Input 2 | Sample Output 2 |
---|---|
1 A 10 1500 A 1300 B 1400 C 1200 D 1100 A 600 B 700 C 1000 D 900 A 800 B STUDENT_ID_ASC |
600 0 700 0 800 0 900 1 1000 0 1100 1 1200 0 1300 0 1400 0 1500 1 |