• Java实现 蓝桥杯 算法提高 成绩排名


    试题 算法提高 成绩排名

    资源限制
    时间限制:1.0s 内存限制:256.0MB
    问题描述
      小明刚经过了一次数学考试,老师由于忙碌忘记排名了,于是老师把这个光荣的任务交给了小明,小明则找到了聪明的你,希望你能帮他解决这个问题。
    输入格式
      第一行包含一个正整数N,表示有个人参加了考试。接下来N行,每行有一个字符串和一个正整数,分别表示人名和对应的成绩,用一个空格分隔。
    输出格式
      输出一共有N行,每行一个字符串,第i行的字符串表示成绩从高到低排在第i位的人的名字,若分数一样则按人名的字典序顺序从小到大。
    样例输入
    3
    aaa 47
    bbb 90
    ccc 70
    样例输出
    bbb
    ccc
    aaa 【数据规模和约定】
    人数<=100,分数<=100,人名仅包含小写字母。

    PS:最后一个测试点有相同名字的人,注意一下,很多人都倒在最后一个测试点了

    
    import java.util.*;
    
    public class chengjipaiming {
     public  static Map<String,Integer> map = new TreeMap<>();
      public static Set<Integer> set = new TreeSet<>();
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
    
            int n = sc.nextInt();
            if (n==0) System.exit(0);
            for (int i=0;i<n;i++){
                String s = sc.next();
                int a = sc.nextInt();
                while (map.containsKey(s)){
                    s=s+1;
                }
                map.put(s,a);
                set.add(a);
            }
            sc.close();
            ArrayList<Integer> list = new ArrayList<Integer>();
            for (int num:set){
                list.add(num);
            }
            for (int i=list.size()-1;i>=0;i--){
                select(list.get(i));
            }
        }
        public static void select(int num){
            for (String s:map.keySet()){
                if (map.get(s)==num){
                    while (s.charAt(s.length()-1)=='1'){
                        s=s.substring(0,s.length()-1);
                    }
                    System.out.println(s);
                }
            }
        }
    }
    
    
  • 相关阅读:
    LOJ 2553 「CTSC2018」暴力写挂——边分治+虚树
    hdu 1028 & hdu 1398 —— 整数划分(生成函数)
    bzoj 4827 [Hnoi2017] 礼物 —— FFT
    bzoj 4503 两个串 —— FFT
    bzoj 3527 [Zjoi2014] 力 —— FFT
    bzoj 3160 万径人踪灭 —— FFT
    bzoj 2194 快速傅立叶之二 —— FFT
    bzoj 2179 FFT快速傅立叶 —— FFT
    洛谷 P3803 多项式乘法(FFT) —— FFT
    CF 1009 F Dominant Indices —— 长链剖分+指针
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13075811.html
Copyright © 2020-2023  润新知