結果

問題 No.267 トランプソート
ユーザー kapokapo
提出日時 2016-05-09 18:23:50
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,309 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 22,528 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 14:55:43
合計ジャッジ時間 1,255 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 0 ms
6,940 KB
testcase_04 AC 0 ms
6,940 KB
testcase_05 AC 0 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 0 ms
6,944 KB
testcase_11 AC 0 ms
6,944 KB
testcase_12 AC 0 ms
6,940 KB
testcase_13 AC 0 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 0 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 0 ms
6,940 KB
testcase_20 AC 0 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:62:25: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[3]’ [-Wformat=]
   62 |                 scanf("%s", &t[i]);
      |                        ~^   ~~~~~
      |                         |   |
      |                         |   char (*)[3]
      |                         char *
main.c:60:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |         scanf("%d", &n);
      |         ^~~~~~~~~~~~~~~
main.c:62:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |                 scanf("%s", &t[i]);
      |                 ^~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

int calc(char *a)
{
	int x = 0;

	if( a[0] == 'D') { x += 0; }
	else if( a[0] == 'C' ) { x += 13; }
	else if( a[0] == 'H' ) { x += 26; }
	else if( a[0] == 'S' ) { x += 39; }

	if( a[1] == 'A') { x += 1; }
	else if( a[1] == '2') { x += 2; }
	else if( a[1] == '3') { x += 3; }
	else if( a[1] == '4') { x += 4; }
	else if( a[1] == '5') { x += 5; }
	else if( a[1] == '6') { x += 6; }
	else if( a[1] == '7') { x += 7; }
	else if( a[1] == '8') { x += 8; }
	else if( a[1] == '9') { x += 9; }
	else if( a[1] == 'T') { x += 10; }
	else if( a[1] == 'J') { x += 11; }
	else if( a[1] == 'Q') { x += 12; }
	else if( a[1] == 'K') { x += 13; }

	return x;
}

void change(char *a, char *b)
{
	char c[3];
	strcpy(c, a);
	strcpy(a, b);
	strcpy(b, c);
}

void sort(int left, int right, char (*s)[3])
{
	if( left >= right ) return;
	int p = left, k = left+1, x, y;
	x = calc( s[left] );
	while( k <= right ) {
		y = calc( s[k] );
		if( x > y ) {
			change( s[p+1], s[k] );
			p++;
		}
		k++;
	}
	change( s[left], s[p] );
	sort( left, p-1, s);
	sort( p+1, right, s);
}

int main(void)
{
	int i, n;
	char t[52][3];
	scanf("%d", &n);
	for( i = 0; i < n; i++) {
		scanf("%s", &t[i]);
	}

	sort(0, n-1, t);

	for( i = 0; i < n-1; i++) printf("%s ", t[i]);
	printf("%s\n", t[n-1]);

	return 0;
}
0