結果

問題 No.273 回文分解
ユーザー YamaKasa
提出日時 2018-09-08 18:30:35
言語 Java
(openjdk 23)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 734 bytes
コンパイル時間 2,104 ms
コンパイル使用メモリ 75,088 KB
実行使用メモリ 54,612 KB
最終ジャッジ日時 2024-12-17 15:59:10
合計ジャッジ時間 7,384 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		scan.close();
		if(S.length() == 2) {
			System.out.println(1);
			System.exit(0);
		}
		int N = S.length();
		for(int i = N - 1; i >= 2; i--) {
			for(int j = 0; j <= N - i; j++) {
				String s = S.substring(j, j + i);
				//System.out.println(s);
				boolean flag = true;
				for(int k = 0; k < s.length() / 2; k++) {
					char c1 = s.charAt(k);
					char c2 = s.charAt(s.length() - k - 1);
					if(c1 != c2) {
						flag = false;
						break;
					}
				}
				if(flag) {
					System.out.println(s.length());
					System.exit(0);
				}
			}
		}
		System.out.println(1);
	}
}
0