• 문제 링크
https://www.acmicpc.net/problem/10489
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Stack<Integer> stk = new Stack<>();
int n = read();
while (n-- > 0) {
int i = read();
if (!stk.isEmpty() && (stk.peek() + i & 1) == 0) stk.pop();
else stk.push(i);
}
bw.write(String.valueOf(stk.size()));
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' 카테고리의 다른 글
[백준] 30068 Stovėjimo aikštelė - Data Structure / Java (0) | 2024.08.25 |
---|---|
[백준] 29934 Important Messages - Data Structure / Java (0) | 2024.08.24 |
[백준] 8538 Bałagan i Stonki - Data Structure / Java (0) | 2024.08.22 |
[백준] 13650 Botas perdidas - Data Structure / Java (0) | 2024.08.21 |
[백준] 22477 Kagisys - Data Structure / Java (0) | 2024.08.20 |
댓글