题解 | #小白鼠排队#用个treemap就行

小白鼠排队

https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b

import java.util.Comparator;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, String> mouses = new TreeMap<>(Comparator.comparingInt(
                    Integer::intValue).reversed());
        while (n-- > 0) {
            int weight = sc.nextInt();
            String color = sc.next();
            mouses.put(weight, color);
        }
        for (String color : mouses.values()) {
            System.out.println(color);
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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