結果

問題 No.267 トランプソート
ユーザー kongarishisyamo
提出日時 2016-05-24 10:14:54
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,300 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 60,904 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-07 03:45:40
合計ジャッジ時間 1,312 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

void update(char nc,int n[],int *c){
	if(nc=='T') n[(*c)++]=10;
	else if(nc=='A') n[(*c)++]=1;
	else if(nc=='J') n[(*c)++]=11;
	else if(nc=='Q') n[(*c)++]=12;
	else if(nc=='K') n[(*c)++]=13;
	else n[(*c)++]=nc-'0';
}

void printcard(char nc,int n[],int c){
	for(int i=0;i<c;i++){
		if(n[i]==1) cout<<nc<<"A";
		else if(n[i]==10) cout<<nc<<"T";
		else if(n[i]==11) cout<<nc<<"J";
		else if(n[i]==12) cout<<nc<<"Q";
		else if(n[i]==13) cout<<nc<<"K";
		else cout<<nc<<n[i];
		if(i!=c-1) cout<<" ";
	}
}

int main(){

	int hc=0,dc=0,sc=0,cc=0;
	int hn[13],dn[13],sn[13],cn[13];
	int N;
	string mn;

	cin>>N;

	for(int i=0;i<N;i++) {
		cin>>mn;
		if(mn[0]=='D') update(mn[1],dn,&dc);
		else if(mn[0]=='C') update(mn[1],cn,&cc);
		else if(mn[0]=='H') update(mn[1],hn,&hc);
		else if(mn[0]=='S') update(mn[1],sn,&sc);
	}

	int sumc=dc+cc+hc+sc;
	sort(dn,dn+dc);
	sort(cn,cn+cc);
	sort(hn,hn+hc);
	sort(sn,sn+sc);

	if(dc!=0){
		sumc-=dc;
		printcard('D',dn,dc);
		if(dc!=0) cout<<" ";
	}
	if(cc!=0){
		sumc-=cc;
		printcard('C',cn,cc);
		if(cc!=0) cout<<" ";
	}
	if(hc!=0){
		sumc-=hc;
		printcard('H',hn,hc);
		if(hc!=0) cout<<" ";
	}
	if(sc!=0){
		sumc-=sc;
		printcard('S',sn,sc);
		if(sc!=0) cout<<" ";
	}

	cout<<endl;
}

0