题解 | #争夺前五名#

争夺前五名

http://www.nowcoder.com/practice/cd052308a1c44a88ad00255f312c3e14

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num = Integer.parseInt(scan.nextLine());
        String scoresStr = scan.nextLine();
        String[] scoresStrs = scoresStr.split(" ");
        List<Integer> scores = new ArrayList<>();//利用List存储所有学生的成绩
        for(String score : scoresStrs) {
            scores.add(Integer.parseInt(score));
        }
        Collections.sort(scores);//从小到大排序
        for(int i = num - 1; i > num - 6; i--) {//从大到小输出前五个
            System.out.print(scores.get(i) + " ");
        }
    }
}
全部评论

相关推荐

想run的马里奥在学...:这个学历帮你扫平百分之80的障碍,投就完了,这会找不到就等3月暑期一样能找到
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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