結果

問題 No.927 Second Permutation
ユーザー pengin_2000pengin_2000
提出日時 2020-02-20 00:47:29
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 691 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 06:12:58
合計ジャッジ時間 1,016 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
int main()
{
	char x[100005];
	scanf("%s", x);
	int i, j, n = strlen(x);
	int c[10];
	for (i = 0; i < 10; i++)
		c[i] = 0;
	for (i = 0; i < n; i++)
		c[x[i] - '0']++;
	int count = 0;
	for (i = 0; i < 10; i++)
		if (c[i] > 0)
			count++;
	if (count == 1)
	{
		printf("-1\n");
		return 0;
	}
	if (count == 2 && c[0] > 0)
	{
		i = 1;
		while (c[i] == 0)
			i++;
		if (c[i] == 1)
		{
			printf("-1\n");
			return 0;
		}
	}
	j = 9;
	for (i = 0; i < n; i++)
	{
		while (c[j] == 0)
			j--;
		x[i] = j + '0';
		c[j]--;
	}
	i = n - 1;
	while (x[i - 1] == x[i])
		i--;
	i--;
	x[i] ^= x[n - 1];
	x[n - 1] ^= x[i];
	x[i] ^= x[n - 1];
	printf("%s\n", x);
	return 0;
}
0