• 문제 링크
https://www.acmicpc.net/problem/13774
• 풀이 코드
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));
StringBuilder sb = new StringBuilder();
String s;
while ((s = br.readLine()).charAt(0) != '#') sb.append(isPossible(s)).append('\n');
bw.write(sb.toString());
bw.flush();
}
private static String isPossible(String s) {
for (int i = 0; i < s.length(); i++) {
StringBuilder sb = new StringBuilder(s).replace(i, i + 1, "");
if (isPalindrome(sb)) return sb.toString();
}
return "not possible";
}
private static boolean isPalindrome(StringBuilder s) {
int n = s.length() / 2;
for (int i = 0; i < n; i++) if (s.charAt(i) != s.charAt(s.length() - i - 1)) return false;
return true;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 2783 삼각 김밥 - Implementation / Java (0) | 2025.03.09 |
---|---|
[백준] 13280 Selection of Participants of an Experiment - Brute Force / Java (0) | 2025.03.08 |
[백준] 32290 MEX vs OR - Brute Force / Java (0) | 2025.03.06 |
[백준] 10372 Alarm Clock - Brute Force / Java (0) | 2025.03.05 |
[백준] 10472 공간을 만들어 봅시다 - Brute Force / Java (0) | 2025.03.04 |
댓글