結果

問題 No.170 スワップ文字列(Easy)
コンテスト
ユーザー bal4u
提出日時 2019-04-13 20:31:52
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 594 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 305 ms
コンパイル使用メモリ 37,120 KB
最終ジャッジ日時 2026-02-22 02:56:29
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// yukicoder: No.170 スワップ文字列(Easy)
// 2019.4.13 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char s[10]; int w;
char t[10];
char f[10];
int ans;

int cmp(const void *a, const void *b) { return *(char *)a - *(char *)b; }

void rec(int id)
{
	int i;
	if (id == w) { ans++; return; }
	for (i = 0; i < w; i++) {
		if (f[i]) continue;
		if (s[i] == t[id]) continue;
		f[i] = 1;
		t[id] = s[i];
		rec(id + 1);
		f[i] = 0;
	}
	t[id] = 0;
}

int main()
{
	scanf("%s", s);
	w = strlen(s);
	qsort(s, w, sizeof(char), cmp);
	rec(0);
	printf("%d\n", ans-1);
	return 0;
}
0