HW7.3

HW7.3

 public class Solution
 {
     public static void main(String[] args)
     {
         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'}
         };

         char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};
         int[] students = new int[10];
         int[] correctCount = new int[10];
         int temp;

         for(int i = 0; i < 10; i++)
             students[i] = i;
         for(int i = 0; i < answers.length; i++)
         {
             for(int j = 0; j < answers[i].length; j++)
                 if(answers[i][j] == keys[j])
                     correctCount[i]++;
         }

         for(int i = 0; i < 10; i++)
         {
             for(int j = i; j < 10; j++)
             {
                 if(correctCount[j] > correctCount[i])
                 {
                     temp = correctCount[j];
                     correctCount[j] = correctCount[i];
                     correctCount[i] = temp;
                     temp = students[j];
                     students[j] = students[i];
                     students[i] = temp;
                 }
             }
         }

         for(int i = 0; i < 10; i++)
             System.out.println("Student " + students[i] + "'s correct count is " + correctCount[i]);
     }
 }
上一篇:多校5 HDU5787 K-wolf Number 数位DP


下一篇:优化studio的速度