結果
| 問題 |
No.267 トランプソート
|
| コンテスト | |
| ユーザー |
kapo
|
| 提出日時 | 2016-05-09 18:23:50 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 1,309 bytes |
| コンパイル時間 | 259 ms |
| コンパイル使用メモリ | 22,784 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-05 13:07:38 |
| 合計ジャッジ時間 | 1,205 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
コンパイルメッセージ
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]);
| ^~~~~~~~~~~~~~~~~~
ソースコード
#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;
}
kapo