题解 | #排名#写个while循环就行

排名

https://www.nowcoder.com/practice/f7c80167c5b04fd2ac4b6d7080a73f01

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
    private static class Student {
        private final String id;
        private final int score;
        private Student(String id, int score) {
            this.id = id;
            this.score = score;
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int N = sc.nextInt();
            if (N == 0) break;
            int M = sc.nextInt();
            int G = sc.nextInt();
            int[] scores = new int[M + 1];
            for (int i = 1; i <= M; i++) {
                scores[i] = sc.nextInt();
            }
            List<Student> students = new ArrayList<>();
            while (N-- != 0) {
                String id = sc.next();
                int m = sc.nextInt();
                int sum = 0;
                while (m-- != 0) {
                    int index = sc.nextInt();
                    sum += scores[index];
                }
                if (sum >= G) students.add(new Student(id, sum));
            }
            System.out.println(students.size());
            students.stream().sorted((o1,
                                      o2) -> o1.score == o2.score ? o1.id.compareTo(o2.id) : o2.score -
                                     o1.score).forEach(student -> System.out.println(student.id + " " +
                                             student.score));
        }
    }
}

全部评论

相关推荐

02-21 23:34
已编辑
厦门大学 Java
神哥不得了:神哥来啦~首先你的bg的话应该算是很好的了,可以把其他删掉,不需要手搓项目呀,直接找网上的项目看懂就行,第一个项目的话虽然和JAVA没有关系,但是他的星数很多,说明你的编程能力还是很强的,我觉得第一个项目是可以放上去的,但是第二个项目的话建议还是再换一个高质量的项目,感觉如果你再把高频top 50的八股再巩固几遍,完全有机会在没有实习的情况下,从暑期实习的大厂,机会还是很大的,注意别看一些假高频八股就行
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务