結果

問題 No.267 トランプソート
ユーザー yudedakoyudedako
提出日時 2015-10-31 10:46:36
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,519 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 74,884 KB
実行使用メモリ 4,484 KB
最終ジャッジ日時 2023-10-11 07:07:08
合計ジャッジ時間 4,237 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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.at(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, l - 1); sort(vector, l, 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