結果

問題 No.267 トランプソート
ユーザー Mcpu3Mcpu3
提出日時 2018-10-20 19:10:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,749 bytes
コンパイル時間 511 ms
コンパイル使用メモリ 65,624 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 05:18:16
合計ジャッジ時間 2,262 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

struct s {
	int mark, number;
};

void encode(char tmp1, char tmp2, s *card) {
	if (tmp1 == 'D') card->mark = 1;
	else if (tmp1 == 'C') card->mark = 2;
	else if (tmp1 == 'H') card->mark = 3;
	else card->mark = 4;
	if (tmp2 == 'A') card->number = 1;
	else if (tmp2 == 'T') card->number = 10;
	else if (tmp2 == 'J') card->number = 11;
	else if (tmp2 == 'Q') card->number = 12;
	else if (tmp2 == 'K') card->number = 13;
	else card->number = tmp2 - '0';
}

void decode(char *tmp1, char *tmp2, s card) {
	if (card.mark == 1) *tmp1 = 'D';
	else if (card.mark == 2) *tmp1 = 'C';
	else if (card.mark == 3) *tmp1 = 'H';
	else *tmp1 = 'S';
	if (card.number == 1) *tmp2 = 'A';
	else if (card.number == 10) *tmp2 = 'T';
	else if (card.number == 11) *tmp2 = 'J';
	else if (card.number == 12) *tmp2 = 'Q';
	else if (card.number == 13) *tmp2 = 'K';
	else *tmp2 = card.number + '0';
}

void insertionSort_mark(int N, s card[]) {
	int j;
	s tmp;
	for (int i = 1; i < N; ++i) {
		tmp = card[i];
		for (j = i - 1; j >= 0 && card[j].mark > tmp.mark; --j) card[j + 1] = card[j];
		card[j + 1] = tmp;
	}
}

void insertionSort_number(int N, s card[]) {
	int j;
	s tmp;
	for (int i = 1; i < N; ++i) {
		tmp = card[i];
		for (j = i - 1; j >= 0 && card[j].number > tmp.number; --j) card[j + 1] = card[j];
		card[j + 1] = tmp;
	}
}

int main() {
	char tmp1, tmp2;
	int N;
	s card[52];
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> tmp1 >> tmp2;
		encode(tmp1, tmp2, &card[i]);
	}
	insertionSort_number(N, card);
	insertionSort_mark(N, card);
	for (int i = 0; i < N; ++i) {
		decode(&tmp1, &tmp2, card[i]);
		if (i > 0) cout << " ";
		cout << tmp1 << tmp2;
	}
}
0