結果

問題 No.273 回文分解
ユーザー Grenache
提出日時 2015-08-28 22:41:08
言語 Java
(openjdk 23)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 882 bytes
コンパイル時間 3,626 ms
コンパイル使用メモリ 77,612 KB
実行使用メモリ 54,460 KB
最終ジャッジ日時 2024-06-25 13:25:25
合計ジャッジ時間 9,289 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder273 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] s = sc.next().toCharArray();
        int n = s.length;
        int max = 1;
        for (int i = 0; i < n; i++) {
        	for (int j = i + 1; j < n - 1; j++) {
        		max = Math.max(max, check(s, i, j));
        	}
        }
        for (int i = 1; i < n; i++) {
        	for (int j = i + 1; j < n; j++) {
        		max = Math.max(max, check(s, i, j));
        	}
        }

        System.out.println(max);

        sc.close();
    }

	private static int check(char[] s, int i, int j) {
		int n = (j - i + 1) / 2;
		boolean flag = true;
		for (int k = 0; k < n; k++) {
			if (s[i + k] != s[j - k]) {
				flag = false;
				break;
			}
		}
		
		if (flag) {
			return j - i + 1;
		} else {
			return 0;
		}
	}
}
0