結果

問題 No.267 トランプソート
ユーザー yudedakoyudedako
提出日時 2015-10-31 10:30:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,516 bytes
コンパイル時間 979 ms
コンパイル使用メモリ 76,948 KB
実行使用メモリ 4,488 KB
最終ジャッジ日時 2023-10-11 07:06:56
合計ジャッジ時間 2,303 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
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 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <map>
#include <vector>
enum Sute {
	D, C, H, S
};
class Card {
public:
	Card(const std::string &arg = "D1") {
		switch (arg.front()) {
		case('D') :
			sute = D;
			break;
		case('C') :
			sute = C;
			break;
		case('H') :
			sute = H;
			break;
		case('S') :
			sute = S;
			break;
		}
		num = map[arg.back()];
		expression = arg;
	}
	bool operator<(const Card &other) {
		return (sute < other.sute) || ((sute == other.sute) && (num < other.num));
	}
	Sute sute;
	int num;
	std::string expression;
	static std::map<const char, int> map;
};
std::map<const char, int> Card::map = {
	{'A', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'T', 10}, {'J', 11}, {'Q', 12}, {'K', 13}
};

void sort(std::vector<Card> &vector, const int &left, const int &right) {
	if (left < right) {
		auto l = left, r = right, pivot = (left + right) / 2;
		while (l < r) {
			while (vector.at(l) < vector.at(pivot))++l;
			while (vector.at(pivot) < vector.at(r))--r;
			if (l < r) {
				auto temp = vector.at(l);
				vector.at(l) = vector.at(r); vector.at(r) = temp;
				++l; --r;
			}
		}
		sort(vector, left, r); sort(vector, r + 1, right);
	}
}
int main() {
	int n;
	std::cin >> n;
	std::vector<Card> vector(n);
	for (auto &i : vector) {
		std::string s;
		std::cin >> s;
		i = Card(s);
	}
	sort(vector, 0, n - 1);
	std::cout << vector.front().expression;
	for (auto i = 1; i < n; ++i) {
		std::cout << " " << vector.at(i).expression;
	}
	return 0;
}
0