結果

問題 No.588 空白と回文
ユーザー YamaKasaYamaKasa
提出日時 2018-09-25 15:06:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 77,204 KB
実行使用メモリ 41,904 KB
最終ジャッジ日時 2024-04-15 04:19:37
合計ジャッジ時間 5,660 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
41,260 KB
testcase_01 AC 113 ms
41,244 KB
testcase_02 AC 114 ms
41,644 KB
testcase_03 AC 121 ms
41,480 KB
testcase_04 AC 98 ms
41,520 KB
testcase_05 AC 116 ms
41,460 KB
testcase_06 AC 115 ms
41,152 KB
testcase_07 AC 115 ms
41,712 KB
testcase_08 AC 118 ms
41,352 KB
testcase_09 AC 112 ms
41,344 KB
testcase_10 AC 104 ms
41,592 KB
testcase_11 AC 127 ms
41,596 KB
testcase_12 AC 121 ms
41,528 KB
testcase_13 AC 116 ms
41,344 KB
testcase_14 AC 118 ms
41,456 KB
testcase_15 AC 112 ms
41,904 KB
testcase_16 AC 106 ms
41,412 KB
testcase_17 AC 128 ms
41,160 KB
testcase_18 AC 113 ms
41,652 KB
testcase_19 AC 114 ms
41,560 KB
testcase_20 AC 122 ms
41,580 KB
testcase_21 AC 132 ms
41,692 KB
testcase_22 AC 125 ms
41,492 KB
testcase_23 AC 130 ms
41,552 KB
testcase_24 AC 108 ms
41,172 KB
権限があれば一括ダウンロードができます

ソースコード

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();
		int l = S.length();
		char[]c1 = new char[l];
		char[]c2 = new char[l];
		for(int i = 0; i < l; i++) {
			c1[i] = S.charAt(i);
			c2[i] = S.charAt(l - i - 1);
		}
		int max = 0;
		for(int i = 0; i < l; i++) {
			int cnt = 0;
			for(int j = i; j < l; j++) {
				if(c1[j] == c2[j - i]) {
					cnt++;
				}
			}
			max = Math.max(max, cnt);
		}
		for(int i = 0; i < l; i++) {
			int cnt = 0;
			for(int j = i; j < l; j++) {
				if(c2[j] == c1[j - i]) {
					cnt++;
				}
			}
			max = Math.max(max, cnt);
		}
		System.out.println(max);
	}
}
0