ZeroRadish

[백준] 1254번 팰린드롬 만들기(JAVA) 본문

카테고리 없음

[백준] 1254번 팰린드롬 만들기(JAVA)

ZeroRadish Etc 2024. 7. 12. 23:44

https://www.acmicpc.net/problem/1254

 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        String s = new BufferedReader(new InputStreamReader(System.in)).readLine();
        int n = s.length();
        int minLen = 2 * n - 1;
        for (int i = 0; i < n; i++) {
            boolean isPalindrome = true;
            for (int j = 0; j < (n - i) / 2; j++) {
                if (s.charAt(i + j) != s.charAt(n - 1 - j)) {
                    isPalindrome = false;
                    break;
                }
            }
            if (isPalindrome) {
                minLen = n + i;
                break;
            }
        }
        System.out.println(minLen);
    }
}
Comments