結果

問題 No.267 トランプソート
ユーザー femto
提出日時 2016-01-16 19:32:15
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,158 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 72,328 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-19 20:14:44
合計ジャッジ時間 1,525 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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