zoukankan      html  css  js  c++  java
  • 按考分对学生排序 Exercise08_03

     1 /**
     2  * @author 冰樱梦
     3  * 时间:2018年12月
     4  * 题目:按考分对学生排序
     5  *
     6  */
     7 public class Exercise08_03 {
     8     public static void main(String args[]) {
     9         int names[]=new int[8];
    10         int[] list=new int[8];
    11         // Students' answers to the questions
    12         char[][] answers = {
    13                 {'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
    14                 {'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},
    15                 {'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'},
    16                 {'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'},
    17                 {'A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
    18                 {'B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
    19                 {'B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
    20                 {'E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}};
    21 
    22         // Key to the questions
    23         char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};
    24 
    25         // Grade all answers
    26         for (int i = 0; i < answers.length; i++) {
    27             // Grade one student
    28             int correctCount = 0;
    29             for (int j = 0; j < answers[i].length; j++) {
    30                 if (answers[i][j] == keys[j])
    31                     correctCount++;
    32             }
    33             list[i]=correctCount;
    34             names[i]=i;
    35 
    36             
    37         }
    38 
    39         BubbleSort(list,names);
    40     }
    41     
    42     //冒泡排序从大到小,稍微修改了一下程序,让名字跟着分数一起排序。
    43     public static void BubbleSort(int[] scores,int[] names){
    44         for(int i=scores.length-1;i>=0;i--){
    45             for(int j=0;j<scores.length-i-1;j++){
    46                 if(scores[j]>scores[j+1]){
    47                     int temp=scores[j];
    48                     scores[j]=scores[j+1];
    49                     scores[j+1]=temp;
    50                     
    51                     int tem=names[j];
    52                     names[j]=names[j+1];
    53                     names[j+1]=tem;
    54                 }
    55             }
    56         }
    57         for(int i=0;i<names.length;i++){
    58             System.out.println("Student " + names[i]);
    59         }
    60         
    61     }
    62 
    63 
    64 
    65 }
  • 相关阅读:
    Oracle学习(四)--sql及sql分类讲解
    Oracle学习(三)--数据类型及常用sql语句
    Oracle学习(二)--启动与关闭
    Tomcat学习笔记--启动成功访问报404错误
    有关Transaction not successfully started问题解决办法
    百度富文本编辑器UEditor1.3上传图片附件等
    hibernate+junit测试实体类生成数据库表
    js登录与注册验证
    SVN安装配置与使用
    [LeetCode] #38 Combination Sum
  • 原文地址:https://www.cnblogs.com/cherrydream/p/10174181.html
Copyright © 2011-2022 走看看