• 문제 링크
18295번: Ants
Charles is fascinated by ants. In order to observe a colony of ants over a long period, Charles managed to build a program that uniquely identifies each ant, using image recognition. (Yes, every ant is unique.) Inside the program, each ant is tagged with a
www.acmicpc.net
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
boolean[] arr = new boolean[1000001];
int n = Integer.parseInt(br.readLine());
while (n-- > 0) {
String x = br.readLine();
if (x.charAt(0) == '-' || x.length() > 6) continue;
arr[Integer.parseInt(x)] = true;
}
int i = -1;
while (++i < arr.length) if (!arr[i]) break;
bw.write(String.valueOf(i));
bw.flush();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 1681 줄 세우기 - Brute Force / Java (0) | 2024.02.24 |
---|---|
[백준] 18312 시각 - Brute Force / Java (0) | 2024.02.23 |
[백준] 29994 Investigating Zeroes and Ones - Dynamic Programming / Java (0) | 2024.02.21 |
[백준] 14767 Flow Shop - Dynamic Programming / Java (0) | 2024.02.20 |
[백준] 7515 Prehistoric Operating Systems - Dynamic Programming / Java (0) | 2024.02.19 |
댓글