結果
| 問題 |
No.267 トランプソート
|
| コンテスト | |
| ユーザー |
rsk0315
|
| 提出日時 | 2019-05-18 16:29:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,000 ms |
| コード長 | 950 bytes |
| コンパイル時間 | 1,228 ms |
| コンパイル使用メモリ | 78,992 KB |
| 最終ジャッジ日時 | 2025-01-07 03:45:14 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | scanf("%zu", &n);
| ~~~~~^~~~~~~~~~~
main.cpp:37:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
37 | scanf("%s", buf);
| ~~~~~^~~~~~~~~~~
ソースコード
#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');
}
rsk0315