题解 | 分数线划定

分数线划定

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        int t = (int) (m * 1.5);

        List<Candidate> candidates = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            int k = in.nextInt();
            int s = in.nextInt();

            candidates.add(new Candidate(k, s));
        }

        // 排序
        candidates.sort((o1, o2) -> {
            return o1.score != o2.score ? o2.score.compareTo(o1.score) : o1.id.compareTo(o2.id);
        });

        // 分数线
        int line = candidates.get(t - 1).score;
        int cnt = 0;    // 输出cnt行
        List<Candidate> passedCandidates = new ArrayList<>();
        for(Candidate candidate : candidates) {
            if(candidate.score >= line) {
                passedCandidates.add(candidate);
                cnt++;
            }
        }
        System.out.println(line + " " + cnt);
        passedCandidates.forEach(e -> System.out.println(e.id + " " + e.score));
    }


}

class Candidate {
    Integer id;
    Integer score;

    public Candidate(Integer id, Integer score) {
        this.id = id;
        this.score = score;
    }
}

全部评论

相关推荐

01-19 12:48
门头沟学院 C++
只想搞钱的鸽子很喜欢...:混账是很多的,还有那些在自己风华正茂的年纪说风凉话讥讽那些下岗前员工的。这些人都是现在职场环境这么烂的帮凶
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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