結果

問題 No.267 トランプソート
ユーザー カルロスカルロス
提出日時 2015-09-23 13:42:10
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 2,208 bytes
コンパイル時間 605 ms
コンパイル使用メモリ 25,136 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 14:35:46
合計ジャッジ時間 2,111 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <string.h>

void Quicksort(int data[], int left, int right){
	int l = left, r = right;
	int pivot = data[(left + right) / 2];
	int temp;

	while(1){
		while (data[l] < pivot) l++;
		while (pivot < data[r]) r--;
		if(r < l) break;

		temp = data[l];
		data[l] = data[r];
		data[r] = temp;

		l++, r--;
	}
	if(left < r)  Quicksort(data, left, r);
	if(l < right) Quicksort(data, l, right);
}

int main(void){
	int i, N, m, n, s;
	scanf("%d", &N);
	int card[N];
	getchar();
	for(i=0;i<N;i++){
		card[i] = 0;
		m = getchar(), n = getchar(), s = getchar();
		if(n=='A'){
			card[i] = 1;
		}else if(n=='T'){
			card[i] = 10;
		}else if(n=='J'){
			card[i] = 11;
		}else if(n=='Q'){
			card[i] = 12;
		}else if(n=='K'){
			card[i] = 13;
		}else{
			card[i] = n - '0';
		}

		if(m=='C'){
			card[i] += 13;
		}else if(m=='H'){
			card[i] += 26;
		}else if(m=='S'){
			card[i] += 39;
		}
	}
	Quicksort(card, 0, N-1);
	for(i=0;i<N;i++){
		if(card[i]<=13){
			printf("D");
			if(card[i]==1){
				printf("A");
			}else if(card[i]==10){
				printf("T");
			}else if(card[i]==11){
				printf("J");
			}else if(card[i]==12){
				printf("Q");
			}else if(card[i]==13){
				printf("K");
			}else{
				printf("%d", card[i]);
			}
		}else if(card[i]<=26){
			printf("C");
			card[i] -= 13;
			if(card[i]==1){
				printf("A");
			}else if(card[i]==10){
				printf("T");
			}else if(card[i]==11){
				printf("J");
			}else if(card[i]==12){
				printf("Q");
			}else if(card[i]==13){
				printf("K");
			}else{
				printf("%d", card[i]);
			}
		}else if(card[i]<=39){
			printf("H");
			card[i] -= 26;
			if(card[i]==1){
				printf("A");
			}else if(card[i]==10){
				printf("T");
			}else if(card[i]==11){
				printf("J");
			}else if(card[i]==12){
				printf("Q");
			}else if(card[i]==13){
				printf("K");
			}else{
				printf("%d", card[i]);
			}
		}else{
			printf("S");
			card[i] -= 39;
			if(card[i]==1){
				printf("A");
			}else if(card[i]==10){
				printf("T");
			}else if(card[i]==11){
				printf("J");
			}else if(card[i]==12){
				printf("Q");
			}else if(card[i]==13){
				printf("K");
			}else{
				printf("%d", card[i]);
			}
		}
		if(i<N-1) printf(" ");
	}
	printf("\n");
	return 0;
}
0