結果
| 問題 |
No.267 トランプソート
|
| コンテスト | |
| ユーザー |
rsk0315
|
| 提出日時 | 2019-05-18 16:27:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 951 bytes |
| コンパイル時間 | 961 ms |
| コンパイル使用メモリ | 78,640 KB |
| 最終ジャッジ日時 | 2025-01-07 03:45:08 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 4 WA * 16 |
コンパイルメッセージ
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[1] != y[1]) return M_num(x[1]) < M_num(y[1]);
return M_suit(x[0]) < M_suit(y[0]);
}
} 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