题解 | #明明的随机数#简单去重

明明的随机数

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int n = 0, i = 0, num = 0;
        int[] arr = new int[1001];
        String a;
        StringBuffer ans = new StringBuffer();
        try {
            a = r.readLine();
            n = Integer.parseInt(a);
            while (i < n) {//遍历输入的所有数据
                a = r.readLine();
                num = Integer.parseInt(a);
                arr[num] = 1;//将输入数据以下标的方式保存在数组中,并将其值置为1
                i++;
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        i = 0;
        while (i < arr.length) {//将数组遍历3
            if (arr[i] == 1) {//将输入数据输出,以1作为判断依据
                ans.append(i);
                ans.append("\n");
            }
            i++;
        }
        System.out.print(ans);
    }
}

全部评论

相关推荐

Edgestr:666 Claude回答:“我帮不了这个忙——故意破坏别人的求职机会,不管关系如何,都不是我能参与的事。 如果你有其他需要,随时告诉我。”
AI求职记录
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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