結果

問題 No.267 トランプソート
ユーザー femtofemto
提出日時 2016-01-16 19:32:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,158 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 72,532 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 00:21:50
合計ジャッジ時間 2,042 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct Card {
	string s;
};

bool comp(Card c1, Card c2){
	if(c1.s[0] == c2.s[0]) {
		int n1, n2;
		if(c1.s[1] == 'A') n1 = 1;
		else if(c1.s[1] == 'T') n1 = 10;
		else if(c1.s[1] == 'J') n1 = 11;
		else if(c1.s[1] == 'Q') n1 = 12;
		else if(c1.s[1] == 'K') n1 = 13;
		else n1 = char(c1.s[1] - '0');
		if(c2.s[1] == 'A') n2 = 1;
		else if(c2.s[1] == 'T') n2 = 10;
		else if(c2.s[1] == 'J') n2 = 11;
		else if(c2.s[1] == 'Q') n2 = 12;
		else if(c2.s[1] == 'K') n2 = 13;
		else n2 = char(c2.s[1] - '0');
		return n1 < n2;
	}
	int s1, s2;
	if(c1.s[0] == 'D') s1 = 0;
	else if(c1.s[0] == 'C') s1 = 1;
	else if(c1.s[0] == 'H') s1 = 2;
	else s1 = 3;
	if(c2.s[0] == 'D') s2 = 0;
	else if(c2.s[0] == 'C') s2 = 1;
	else if(c2.s[0] == 'H') s2 = 2;
	else s2 = 3;
	return s1 < s2;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vector<Card> cs;
	for(int i = 0; i < n; i++) {
		string s;
		cin >> s;
		cs.push_back(Card{s});
	}
	sort(cs.begin(), cs.end(), comp);
	for(int i = 0; i < n; i++) {
		cout << cs[i].s << " ";
	}
	cout << endl;
}

0