結果

問題 No.267 トランプソート
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-05-24 10:14:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,300 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 60,664 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 10:35:44
合計ジャッジ時間 1,326 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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