結果

問題 No.447 ゆきこーだーの雨と雪 (2)
ユーザー asugen0402asugen0402
提出日時 2019-04-03 16:17:07
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 4,491 bytes
コンパイル時間 392 ms
コンパイル使用メモリ 31,064 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-23 11:52:25
合計ジャッジ時間 2,869 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_QUIZ_MAX		26										// 最大問題数
#define D_HUMAN_MAX		4000									// 最大参加人数
#define D_NAME_MAX		20										// 最大名前長さ

// 内部構造体 - 問題情報
typedef struct Quiz {
	int miLV;													// レベル
	int miCnt;													// AC数
} Quiz;

// 内部構造体 - 参加者情報
typedef struct Human {
	char mc1Name[D_NAME_MAX];									// 名前
	int mi1Score[D_QUIZ_MAX];									// スコア
	int miSum;													// スコア合計
	int miTime;													// 最終AC時間
} Human;

// 内部変数
static FILE *szpFpI;											// 入力
static Quiz sz1Quiz[D_QUIZ_MAX];								// 問題
static int siQCnt;												// 問題数
static Human sz1Human[D_HUMAN_MAX];								// 参加者
static int siHCnt;												// 参加者数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// 出力
int
fOut(
	char *pcpLine				// <I> 1行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// ソート関数 - スコア合計降順 - 最終AC時間昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値1
	, const void *pzpVal2		// <I> 値2
)
{
	Human *lzpVal1 = (Human *)pzpVal1;
	Human *lzpVal2 = (Human *)pzpVal2;

	// スコア合計降順
	if (lzpVal1->miSum > lzpVal2->miSum) {
		return -1;
	}
	else if (lzpVal1->miSum < lzpVal2->miSum) {
		return 1;
	}

	// 最終AC時間昇順
	if (lzpVal1->miTime > lzpVal2->miTime) {
		return 1;
	}
	else if (lzpVal1->miTime < lzpVal2->miTime) {
		return -1;
	}

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i, j;
	char lc1Buf[1024], lc1Out[1024];

	// 問題数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siQCnt);

	// 問題 - 取得
	for (i = 0; i < siQCnt; i++) {
		fscanf(szpFpI, "%d", &sz1Quiz[i].miLV);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 提出数 - 取得
	int liCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &liCnt);

	// 提出 - 取得
	for (i = 0; i < liCnt; i++) {
		char lc1Name[D_NAME_MAX], lcQuiz;
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%s %c", lc1Name, &lcQuiz);

		// 参加者 - 検索
		Human *lzpHuman = NULL;
		for (j = 0; j < siHCnt; j++) {
			if (!strcmp(sz1Human[j].mc1Name, lc1Name)) {
				lzpHuman = &sz1Human[j];
				break;
			}
		}
		if (lzpHuman == NULL) {
			lzpHuman = &sz1Human[siHCnt];
			siHCnt++;
			strcpy(lzpHuman->mc1Name, lc1Name);
		}

		// 問題
		int liQNo = lcQuiz - 'A';
		sz1Quiz[liQNo].miCnt++;

		// スコア
		lzpHuman->mi1Score[liQNo] = 50 * sz1Quiz[liQNo].miLV + (int)(50.0 * (double)sz1Quiz[liQNo].miLV / (0.8 + 0.2 * (double)sz1Quiz[liQNo].miCnt));
		lzpHuman->miSum += lzpHuman->mi1Score[liQNo];
		lzpHuman->miTime = i;
	}

	// 参加者 - ソート
	qsort(sz1Human, siHCnt, sizeof(Human), fSortFnc);

	// 出力
	for (i = 0; i < siHCnt; i++) {
		sprintf(lc1Out, "%d %s", i + 1, sz1Human[i].mc1Name);
		for (j = 0; j < siQCnt; j++) {
			sprintf(lc1Buf, " %d", sz1Human[i].mi1Score[j]);
			strcat(lc1Out, lc1Buf);
		}
		sprintf(lc1Buf, " %d\n", sz1Human[i].miSum);
		strcat(lc1Out, lc1Buf);
		fOut(lc1Out);
	}

	return 0;
}

// 1回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	memset(sz1Quiz, 0, sizeof(sz1Quiz));						// 問題
	memset(sz1Human, 0, sizeof(sz1Human));						// 参加者
	siHCnt = 0;													// 参加者数

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}

0