結果

問題 No.2234 palindromer
ユーザー pengin_2000pengin_2000
提出日時 2023-03-03 21:49:25
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 499 ms
コンパイル使用メモリ 31,312 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 01:46:47
合計ジャッジ時間 1,351 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
char a[1003];
char ans[2][1003];
int l[2];
int main()
{
	scanf("%s", a);
	int i, j, k;
	int n, v;
	for (n = 0; a[n] != '\0'; n++);
	k = n - 1;
	for (i = n - 1; n - 1 - i <= i; i--)
	{
		v = 0;
		for (j = 1; j + i < n; j++)
			if (a[i + j] != a[i - j])
				v++;
		if (v == 0)
			k = i;
	}
	for (i = 0, l[0] = 0; i <= k; i++, l[0]++)
		ans[0][l[0]] = a[i];
	for (i = k - 1; i >= 0; i--, l[0]++)
		ans[0][l[0]] = a[i];
	ans[0][l[0]] = '\0';
	k = n - 1;
	for (i = n - 1; n - i - 1 <= i + 1; i--)
	{
		v = 0;
		for (j = 1; j + i < n; j++)
			if (a[i + j] != a[i - j + 1])
				v++;
		if (v == 0)
			k = i;
	}
	for (i = 0, l[1] = 0; i <= k; i++, l[1]++)
		ans[1][l[1]] = a[i];
	for (i = k; i >= 0; i--, l[1]++)
		ans[1][l[1]] = a[i];
	ans[1][l[1]] = '\0';
	if (l[0] < l[1])
		printf("%s\n", ans[0]);
	else
		printf("%s\n", ans[1]);
	return 0;
}
0