题解 | 分数线划定

分数线划定

https://www.nowcoder.com/practice/2395fa7b6c6e452e8d8310a7cfdbe902

import java.util.*;
import java.util.stream.Collectors;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        String[] s1 = s.split(" ");
        //报名人数与计划录取人数
        int a = Integer.valueOf(s1[0]);
        int b = Integer.valueOf(s1[0]);
        //面试名额
        double c = Integer.valueOf(s1[1]) * 1.5;
        int d = (int) c;
        TreeMap<String, Integer> stringIntegerTreeMap = new TreeMap<>();
        for (int i = 0; i < a; i++) {
            String i1 = in.next();
            int i2 = in.nextInt();
            stringIntegerTreeMap.put(i1, i2);
        }
        Map<String, Integer> collect = stringIntegerTreeMap.entrySet().stream().sorted(Map.Entry.<String, Integer>comparingByValue().reversed().thenComparing(Map.Entry.comparingByKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,(v1,v2)->v2, LinkedHashMap::new));
        int score=0;
        int count=1;
        for (Map.Entry<String, Integer> stringIntegerEntry : collect.entrySet()) {
            if (count==d){
                score=stringIntegerEntry.getValue();
                break;
            }
            count++;
        }
        int finalScore = score;
        long totalcount = collect.entrySet().stream().filter(e -> e.getValue() >= finalScore).count();
        System.out.println(finalScore+" "+totalcount);
        collect.entrySet().stream().filter(e->e.getValue()>= finalScore).forEach(e-> System.out.println(e.getKey()+" "+e.getValue()));
    }
}

全部评论

相关推荐

01-11 02:09
已编辑
华中师范大学 golang
京京洪洪学java:如果坚定转Java就要先做好暑期结果可能没那么好的准备,大厂也有做go的,也有接受内部切换技术栈的,go怎么就不行了呢?,ACM+华师肯定能接到一些大厂面试的,acm铜的基础可以让你比较轻松地应对中大厂的手撕,就是八股和项目要下硬功夫,至于找不到go项目?github上一直刷啊,跟刷b站主页一样,那么多好的go开源项目,怎么会找不到呢?刷到想学感兴趣的用ai吃透,试着改进或者吸收作为自己的项目,另一个选择就是考研了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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