File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed
Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ # [ Silver II] 팰린드롬 만들기 - 1254
2+
3+ [ 문제 링크] ( https://www.acmicpc.net/problem/1254 )
4+
5+ ### 성능 요약
6+
7+ 메모리: 14256 KB, 시간: 108 ms
8+
9+ ### 분류
10+
11+ 브루트포스 알고리즘, 문자열
12+
13+ ### 제출 일자
14+
15+ 2025년 4월 7일 09:49:01
16+
17+ ### 문제 설명
18+
19+ <p >동호와 규완이는 212호에서 문자열에 대해 공부하고 있다. 규완이는 팰린드롬을 엄청나게 좋아한다. 팰린드롬이란 앞에서부터 읽으나 뒤에서부터 읽으나 같게 읽히는 문자열을 말한다.</p >
20+
21+ <p >동호는 규완이를 위한 깜짝 선물을 준비했다. 동호는 규완이가 적어놓고 간 문자열 S에 0개 이상의 문자를 문자열 뒤에 추가해서 팰린드롬을 만들려고 한다. 동호는 가능하면 가장 짧은 문자열을 만들려고 한다.</p >
22+
23+ <p >동호가 만들 수 있는 가장 짧은 팰린드롬의 길이를 출력하는 프로그램을 작성하시오.</p >
24+
25+ ### 입력
26+
27+ <p >첫째 줄에 문자열 S가 주어진다. S는 알파벳 소문자로만 이루어져 있고, 길이는 최대 50이다.</p >
28+
29+ ### 출력
30+
31+ <p >첫째 줄에 동호가 만들 수 있는 가장 짧은 팰린드롬의 길이를 출력한다.</p >
32+
Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+ static List <Character > s , e ;
6+ static int n ;
7+ static char [] string ;
8+ static BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
9+ public static void main (String [] args ) throws Exception {
10+ preSetting ();
11+ System .out .println (addAlpha ());
12+ }
13+
14+ static int addAlpha (){
15+ for (int i = 0 ; i < n ; i ++){
16+ if (isPalind (i )) return n + i ;
17+ }
18+ return 2 * n ;
19+ }
20+
21+ static boolean isPalind (int s ){
22+ int e = n - 1 ;
23+ while (s <= e ){
24+ if (string [s ++] != string [e --]) return false ;
25+ }
26+ return true ;
27+ }
28+
29+ static void preSetting () throws Exception {
30+ string = br .readLine ().toCharArray ();
31+ n = string .length ;
32+
33+ s = new ArrayList <>();
34+ e = new ArrayList <>();
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments