結果

問題 No.273 回文分解
ユーザー spacia
提出日時 2016-01-13 23:39:26
言語 Java
(openjdk 23)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 2,803 ms
コンパイル使用メモリ 75,284 KB
実行使用メモリ 50,492 KB
最終ジャッジ日時 2024-06-25 13:34:01
合計ジャッジ時間 5,342 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main {
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static boolean isReversible (String s) {
		int len = s.length();
		for (int i = 0; i < len / 2; i++) {
			if (s.charAt(i) != s.charAt(len - i - 1)) return false;
		}
		return true;
	}
	
	public static int solve (String s) {
		int len = s.length();
		for (int i = len - 1; i > 0; i--) {
			for (int j = 0; i + j <= len; j++) {
				String sub = s.substring(j , i + j);
				//out(sub);
				if (isReversible(sub)) return i;
			}
		}
		return 0;
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		out(solve(br.readLine()));
	}
}
0