• 문제 링크
10104번: Party Invitation
The first line of input contains the integer K (1 ≤ K ≤ 100). The second line of input contains the integer m (1 ≤ m ≤ 10), which is the number of rounds of removal. The next m lines each contain one integer. The ith of these lines (1 ≤ i ≤ m)
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int k = read();
List<Integer> list = new ArrayList<>();
for (int i = 1; i <= k; i++) list.add(i);
int m = read();
while (m-- > 0) {
int r = read();
for (int i = 1; i <= list.size(); i++) if (i % r == 0) list.set(i - 1, 0);
Predicate<Integer> filter = new Predicate<Integer>() {
@Override
public boolean test(Integer i) {
return i.equals(0);
}
};
list.removeIf(filter);
}
for (int i : list) sb.append(i).append("\n");
bw.write(sb.toString());
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 6189 Munching - Graph Theory / Java (0) | 2023.12.13 |
---|---|
[백준] 6080 Bad Grass - Graph Theory / Java (0) | 2023.12.12 |
[백준] 25325 학생 인기도 측정 - Data Structure / Java (0) | 2023.12.10 |
[백준] 2605 줄 세우기 - Data Structure / Java (0) | 2023.12.09 |
[백준] 1835 카드 - Data Structure / Java (0) | 2023.12.08 |
댓글