/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main {
public static void main
(String[] args
) { char[][] answers = getStudentsAnswers();
int[][] result = gradeStudentsAnswers(answers);
announceResult(result);
}
/**
* get students' answers for 10 multiple choice questions
* @return student's answers for 10 MCQs
*/
private static char[][] getStudentsAnswers() {
char[][] answers = {
{'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
{'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},
{'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'},
{'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'},
{'A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
{'B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
{'B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
{'E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
};
return answers;
}
/**
* grade students on the basis of number of correct answers
* @param answers student's responses for MCQs
* @return a descending list based on number of correct responses
*/
private static int[][] gradeStudentsAnswers(char[][] answers) {
char[] answerKeys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};
// final list: [student id, student correct responses]
int[][] finalList = new int[answers.length][2];
int i = 0;
for (int studentNo = 0; studentNo < answers.length; ++studentNo) {
int correctAnswers = 0;
for (int answerNo = 0; answerNo < answers[studentNo].length;
++answerNo) {
if (answers[studentNo][answerNo] == answerKeys[answerNo]) {
++correctAnswers;
}
}
finalList[i][0] = studentNo;
finalList[i][1] = correctAnswers;
++i;
}
sortFinalList(finalList);
return finalList;
}
/**
* sorts the student final list on the basis of number of correct responses
* @param finalList list generated after grading
*/
private static void sortFinalList(int[][] finalList) {
// selection sort on the basis of score
for (int row = 0; row < finalList.length - 1; ++row) {
int maximumIndex = row;
for (int col = row + 1; col < finalList.length; ++col) {
if (finalList[col][1] > finalList[row][1]) {
maximumIndex = col;
}
}
if (maximumIndex != row) {
int[] temp = finalList[row];
finalList[row] = finalList[maximumIndex];
finalList[maximumIndex] = temp;
}
}
}
private static void announceResult(int[][] result) {
for (int i = 0; i < result.length; ++i) {
System.
out.
printf("Rank #%d: Student %d, Correct Responses: %d / 10\n",
i + 1, result[i][0], result[i][1]);
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KcHVibGljIGNsYXNzIE1haW4gewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIGNoYXJbXVtdIGFuc3dlcnMgPSBnZXRTdHVkZW50c0Fuc3dlcnMoKTsKICAgICAgICBpbnRbXVtdIHJlc3VsdCA9IGdyYWRlU3R1ZGVudHNBbnN3ZXJzKGFuc3dlcnMpOwogICAgICAgIGFubm91bmNlUmVzdWx0KHJlc3VsdCk7CiAgICB9CgogICAgLyoqCiAgICAgKiBnZXQgc3R1ZGVudHMnIGFuc3dlcnMgZm9yIDEwIG11bHRpcGxlIGNob2ljZSBxdWVzdGlvbnMKICAgICAqIEByZXR1cm4gc3R1ZGVudCdzIGFuc3dlcnMgZm9yIDEwIE1DUXMKICAgICAqLwogICAgcHJpdmF0ZSBzdGF0aWMgY2hhcltdW10gZ2V0U3R1ZGVudHNBbnN3ZXJzKCkgewogICAgICAgIGNoYXJbXVtdIGFuc3dlcnMgPSB7CiAgICAgICAgICAgICAgICB7J0EnLCAnQicsICdBJywgJ0MnLCAnQycsICdEJywgJ0UnLCAnRScsICdBJywgJ0QnfSwKICAgICAgICAgICAgICAgIHsnRCcsICdCJywgJ0EnLCAnQicsICdDJywgJ0EnLCAnRScsICdFJywgJ0EnLCAnRCd9LAogICAgICAgICAgICAgICAgeydFJywgJ0QnLCAnRCcsICdBJywgJ0MnLCAnQicsICdFJywgJ0UnLCAnQScsICdEJ30sCiAgICAgICAgICAgICAgICB7J0MnLCAnQicsICdBJywgJ0UnLCAnRCcsICdDJywgJ0UnLCAnRScsICdBJywgJ0QnfSwKICAgICAgICAgICAgICAgIHsnQScsICdCJywgJ0QnLCAnQycsICdDJywgJ0QnLCAnRScsICdFJywgJ0EnLCAnRCd9LAogICAgICAgICAgICAgICAgeydCJywgJ0InLCAnRScsICdDJywgJ0MnLCAnRCcsICdFJywgJ0UnLCAnQScsICdEJ30sCiAgICAgICAgICAgICAgICB7J0InLCAnQicsICdBJywgJ0MnLCAnQycsICdEJywgJ0UnLCAnRScsICdBJywgJ0QnfSwKICAgICAgICAgICAgICAgIHsnRScsICdCJywgJ0UnLCAnQycsICdDJywgJ0QnLCAnRScsICdFJywgJ0EnLCAnRCd9LAogICAgICAgIH07CgogICAgICAgIHJldHVybiBhbnN3ZXJzOwogICAgfQoKICAgIC8qKgogICAgICogZ3JhZGUgc3R1ZGVudHMgb24gdGhlIGJhc2lzIG9mIG51bWJlciBvZiBjb3JyZWN0IGFuc3dlcnMKICAgICAqIEBwYXJhbSBhbnN3ZXJzIHN0dWRlbnQncyByZXNwb25zZXMgZm9yIE1DUXMKICAgICAqIEByZXR1cm4gYSBkZXNjZW5kaW5nIGxpc3QgYmFzZWQgb24gbnVtYmVyIG9mIGNvcnJlY3QgcmVzcG9uc2VzCiAgICAgKi8KICAgIHByaXZhdGUgc3RhdGljIGludFtdW10gZ3JhZGVTdHVkZW50c0Fuc3dlcnMoY2hhcltdW10gYW5zd2VycykgewogICAgICAgIGNoYXJbXSBhbnN3ZXJLZXlzID0geydEJywgJ0InLCAnRCcsICdDJywgJ0MnLCAnRCcsICdBJywgJ0UnLCAnQScsICdEJ307CiAgICAgICAgLy8gZmluYWwgbGlzdDogW3N0dWRlbnQgaWQsIHN0dWRlbnQgY29ycmVjdCByZXNwb25zZXNdCiAgICAgICAgaW50W11bXSBmaW5hbExpc3QgPSBuZXcgaW50W2Fuc3dlcnMubGVuZ3RoXVsyXTsKICAgICAgICBpbnQgaSA9IDA7CiAgICAgICAgZm9yIChpbnQgc3R1ZGVudE5vID0gMDsgc3R1ZGVudE5vIDwgYW5zd2Vycy5sZW5ndGg7ICsrc3R1ZGVudE5vKSB7CiAgICAgICAgICAgIGludCBjb3JyZWN0QW5zd2VycyA9IDA7CiAgICAgICAgICAgIGZvciAoaW50IGFuc3dlck5vID0gMDsgYW5zd2VyTm8gPCBhbnN3ZXJzW3N0dWRlbnROb10ubGVuZ3RoOwogICAgICAgICAgICAgICAgICsrYW5zd2VyTm8pIHsKICAgICAgICAgICAgICAgIGlmIChhbnN3ZXJzW3N0dWRlbnROb11bYW5zd2VyTm9dID09IGFuc3dlcktleXNbYW5zd2VyTm9dKSB7CiAgICAgICAgICAgICAgICAgICAgKytjb3JyZWN0QW5zd2VyczsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBmaW5hbExpc3RbaV1bMF0gPSBzdHVkZW50Tm87CiAgICAgICAgICAgIGZpbmFsTGlzdFtpXVsxXSA9IGNvcnJlY3RBbnN3ZXJzOwogICAgICAgICAgICArK2k7CiAgICAgICAgfQogICAgICAgIHNvcnRGaW5hbExpc3QoZmluYWxMaXN0KTsKCiAgICAgICAgcmV0dXJuIGZpbmFsTGlzdDsKICAgIH0KCiAgICAvKioKICAgICAqIHNvcnRzIHRoZSBzdHVkZW50IGZpbmFsIGxpc3Qgb24gdGhlIGJhc2lzIG9mIG51bWJlciBvZiBjb3JyZWN0IHJlc3BvbnNlcwogICAgICogQHBhcmFtIGZpbmFsTGlzdCBsaXN0IGdlbmVyYXRlZCBhZnRlciBncmFkaW5nCiAgICAgKi8KICAgIHByaXZhdGUgc3RhdGljIHZvaWQgc29ydEZpbmFsTGlzdChpbnRbXVtdIGZpbmFsTGlzdCkgewogICAgICAgIC8vIHNlbGVjdGlvbiBzb3J0IG9uIHRoZSBiYXNpcyBvZiBzY29yZQogICAgICAgIGZvciAoaW50IHJvdyA9IDA7IHJvdyA8IGZpbmFsTGlzdC5sZW5ndGggLSAxOyArK3JvdykgewogICAgICAgICAgICBpbnQgbWF4aW11bUluZGV4ID0gcm93OwogICAgICAgICAgICBmb3IgKGludCBjb2wgPSByb3cgKyAxOyBjb2wgPCBmaW5hbExpc3QubGVuZ3RoOyArK2NvbCkgewogICAgICAgICAgICAgICAgaWYgKGZpbmFsTGlzdFtjb2xdWzFdID4gZmluYWxMaXN0W3Jvd11bMV0pIHsKICAgICAgICAgICAgICAgICAgICBtYXhpbXVtSW5kZXggPSBjb2w7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKG1heGltdW1JbmRleCAhPSByb3cpIHsKICAgICAgICAgICAgICAgIGludFtdIHRlbXAgPSBmaW5hbExpc3Rbcm93XTsKICAgICAgICAgICAgICAgIGZpbmFsTGlzdFtyb3ddID0gZmluYWxMaXN0W21heGltdW1JbmRleF07CiAgICAgICAgICAgICAgICBmaW5hbExpc3RbbWF4aW11bUluZGV4XSA9IHRlbXA7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgcHJpdmF0ZSBzdGF0aWMgdm9pZCBhbm5vdW5jZVJlc3VsdChpbnRbXVtdIHJlc3VsdCkgewogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgcmVzdWx0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRmKCJSYW5rICMlZDogU3R1ZGVudCAlZCwgQ29ycmVjdCBSZXNwb25zZXM6ICVkIC8gMTBcbiIsCiAgICAgICAgICAgICAgICAgICAgaSArIDEsIHJlc3VsdFtpXVswXSwgcmVzdWx0W2ldWzFdKTsKICAgICAgICB9CiAgICB9Cn0=