• 문제 링크
https://www.acmicpc.net/problem/30614
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Stack;
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));
bw.write(isStable(Integer.parseInt(br.readLine()), br.readLine()) ? '1' : '0');
bw.flush();
}
private static boolean isStable(int n, String s) {
Stack<Character> stk = new Stack<>();
for (int i = 0; i < n; i++) {
char c = s.charAt(i);
if (c > 96) stk.push(c);
else if (stk.isEmpty() || stk.pop() - c != 32) return false;
}
return stk.isEmpty();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 29813 최애의 팀원 - Data Structure / Java (0) | 2025.02.07 |
---|---|
[백준] 17503 맥주 축제 - Data Structure / Java (0) | 2025.02.06 |
[백준] 14455 Don't Be Last! - Data Structure / Java (0) | 2025.02.04 |
[백준] 2511 카드놀이 - Implementation / Java (0) | 2025.02.03 |
[백준] 5218 알파벳 거리 - Implementation / Java (0) | 2025.02.02 |
댓글