結果

問題 No.564 背の順
ユーザー Naoki00712Naoki00712
提出日時 2023-06-13 11:21:00
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 813 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 28,648 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 18:25:21
合計ジャッジ時間 1,253 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int cmp(const void* n1, const void* n2)
{
	if (*(int*)n1 > *(int*)n2) {
		return -1;
	}
	else if (*(int*)n1 < *(int*)n2) {
		return 1;
	}

	return 0;
}


int main()
{
	int h1, N, ans = 0;
	int* H;

	if (scanf("%d %d", &h1, &N) != 2) {
		return -1;
	}

	H = (int*)malloc(sizeof(int) * N);

	if (H == NULL) {
		return -1;
	}

	*(H + 0) = h1;

	for (int i = 1; i < N; i++) {
		if (scanf("%d", &*(H + i)) != 1) {
			return -1;
		}
	}

	qsort(H, N, sizeof(int), cmp);

	for (int i = 0; i < N; i++) {
		if (*(H + i) == h1) {
			ans = i + 1;
			break;
		}
	}

	switch (ans)
	{
	case 1:
		printf("%dst", ans);
		break;
	case 2:
		printf("%dnd", ans);
		break;
	case 3:
		printf("%drd", ans);
		break;
	default:
		printf("%dth", ans);
		break;
	}

	free(H);
	H = NULL;

	return 0;
}
0