結果

問題 No.267 トランプソート
ユーザー rsk0315rsk0315
提出日時 2019-05-18 16:29:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 950 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 77,012 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 07:38:23
合計ジャッジ時間 1,754 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cctype>
#include <vector>
#include <string>
#include <algorithm>

struct {
  int M_num(char x) const {
    if (isdigit(x)) return x-'0';
    if (x == 'A') return 1;
    if (x == 'T') return 10;
    if (x == 'J') return 11;
    if (x == 'Q') return 12;
    if (x == 'K') return 13;
    return -1;
  }
  int M_suit(char x) const {
    if (x == 'D') return 0;
    if (x == 'C') return 1;
    if (x == 'H') return 2;
    if (x == 'S') return 3;
    return -1;
  }
  bool operator ()(const std::string& x, const std::string& y) const {
    if (x[0] != y[0]) return M_suit(x[0]) < M_suit(y[0]);
    return M_num(x[1]) < M_num(y[1]);
  }
} cmp;

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<std::string> a(n);
  for (auto& ai: a) {
    char buf[3];
    scanf("%s", buf);
    ai = buf;
  }

  std::sort(a.begin(), a.end(), cmp);
  for (size_t i = 0; i < n; ++i)
    printf("%s%c", a[i].c_str(), i+1<n? ' ':'\n');
}
0