题解 | #提取不重复的整数# 在牛客学习笔试代码
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
InputStream in = System.in;
int num = 0;
int c;
while ((c = in.read()) != '\n') {
if (c >= '0' && c <= '9') {
num = num * 10 + (c - '0'); // 将字符转换为数字
}
}
int result = 0;
boolean[] seen = new boolean[10]; // 记录数字是否出现过
while (num > 0) {
int digit = num % 10;
if (!seen[digit]) {
result = result * 10 + digit;
seen[digit] = true;
}
num = num / 10;
}
System.out.println(result);
}
}