結果

問題 No.69 文字を自由に並び替え
ユーザー kapokapo
提出日時 2016-04-15 06:52:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 757 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 26,896 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 23:18:11
合計ジャッジ時間 993 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

void quick_sort(char *str, int left, int right);
void change(char &a, char &b);

int main(void)
{
	char a[11], b[11];
	scanf("%s %s", a, b);
	int n; n = (int)strlen(a);

	quick_sort(a, 0, n-1); 
	quick_sort(b, 0, n-1);

	if (strcmp(a, b) == 0) { 
		printf("YES\n");
	} else {
		printf("NO\n");
	}

	return 0;
}

void quick_sort(char *str, int left, int right)
{
	if (left >= right) return;

	int p = left, k = left+1;

	while (k <= right) {

		if ((int)str[left] > (int)str[k]) {
			change(str[p+1], str[k]);
			p++;
		}
		k++;
	}
	change(str[left], str[p]);

	quick_sort(str, left, p-1);
	quick_sort(str, p+1, right);
}

void change(char &a, char &b)
{
	char temp;
	temp = a;
	a = b;
	b = temp;
}
0