题解 | #明明的随机数#

明明的随机数

https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int count = in.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        boolean[] symbol = new boolean[501];
        while(count>0){
            count--;
            int temp = in.nextInt();
            if(temp<=500 && temp>=1 && symbol[temp]==false){
                symbol[temp] = true;
                list.add(temp);
            }
        }
        Integer[] newList = new Integer[list.size()];
        list.toArray(newList);
        Arrays.sort(newList);
        for(int i:newList){
            System.out.println(i);
        }
    }
}

全部评论

相关推荐

09-18 20:41
百度_Java
要个offer怎么这...:哈哈哈哈哈哈,我也拿了0x10000000个offer,秋招温啦啦啦,好开心
我的秋招日记
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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