File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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 String str ;
6+ static int min = Integer .MAX_VALUE ;
7+
8+ public static void main (String [] args ) throws IOException {
9+ Scanner sc = new Scanner (System .in );
10+ str = sc .next ();
11+ solve ();
12+
13+ }
14+
15+ public static void solve () {
16+ for (int i = 0 ; i < str .length (); i ++) {
17+ String left = str .substring (0 , i );
18+ String right = str .substring (i );
19+ action (left , right );
20+ }
21+ System .out .println (min );
22+ }
23+
24+ public static void action (String left , String right ) {
25+ // 일단 right가 팰린드롬이어야 한다.
26+ if (isPalindrom (right )) {
27+ min = Math .min (min , left .length () * 2 + right .length ());
28+ }
29+ }
30+
31+ public static boolean isPalindrom (String right ) {
32+ int mid = right .length () / 2 ;
33+ for (int i = 0 ; i < mid ; i ++) {
34+ if (right .charAt (i ) != right .charAt (right .length () - 1 - i )) {
35+ return false ;
36+ }
37+ }
38+ return true ;
39+ }
40+
41+ }
You can’t perform that action at this time.
0 commit comments