結果
問題 |
No.267 トランプソート
|
ユーザー |
|
提出日時 | 2015-10-31 10:30:01 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,516 bytes |
コンパイル時間 | 688 ms |
コンパイル使用メモリ | 74,976 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-13 06:17:33 |
合計ジャッジ時間 | 1,563 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 WA * 13 |
ソースコード
#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; }