题解 | #成绩排序#

成绩排序

https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            int a = Integer.parseInt(in.nextLine());
            int b = Integer.parseInt(in.nextLine());
            List<Integer> list = new ArrayList<>();
            Map<Integer,List<String>> map = new HashMap<>();
            for(int i=0;i<a;i++){
                String[] str = in.nextLine().split(" ");
                int fen = Integer.parseInt(str[1]);

                if(map.get(fen)==null) {
                    List<String> gg = new ArrayList<>();
                    gg.add(str[0]);
                    map.put(fen,gg);
                }else{
                    map.get(fen).add(str[0]);
                }
                list.add(fen);
            }
            Collections.sort(list);
            if(b==0)Collections.reverse(list);
            int sum =0;
            for(int i = 0;i<list.size();i++){
                if(i>0&&list.get(i)==list.get(i-1))sum++;
                else sum = 0;
                System.out.println(map.get(list.get(i)).get(sum)+" "+list.get(i));
            }
        }
    }
}

全部评论

相关推荐

Java大菜狗:纯纯招黑奴,一天还不到两百那么多要求,还不迟到早退,以为啥啊,给一点工资做一堆活,还以不拖欠员工工资为荣,这是什么值得骄傲的事情吗,纯纯***公司
点赞 评论 收藏
分享
07-03 16:13
嘉应学院 Python
xiaolihuam...:很明显骗子,如果是hr直接约你面试了,哪用得着内推,如果是员工的话,你得多优秀,一线员工直接加你微信,
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-15 17:24
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务