题解 | #明明的随机数#

明明的随机数

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int[] b = new int[500];//根据题目数据范围条件,用数组去重、排序
            for(int i=0;i<a;i++){//根据第一个输入的数字确定载入数组数据的次数
                b[in.nextInt()-1]=1;//【1,500】的数据范围,保存的数组下标范围为【0,499】所以-1,
            }						//也可以用boolean类型的数组保存
            for(int i=0;i<500;i++)
            {
                if(b[i]>0)
                {
                    System.out.println(i+1);
                }
            }
            
        }
    }
}

全部评论

相关推荐

Yki_:以下条件优先录用: 喜欢去缅北当猪仔的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务