結果

問題 No.628 Tagの勢い
ユーザー Mcpu3Mcpu3
提出日時 2018-10-21 15:39:49
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,112 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 20:18:37
合計ジャッジ時間 928 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef struct {
	char word[21];
	int score;
} s;

int compare(const void *x, const void *y)
{
	return ((s*)y)->score - ((s*)x)->score;
}

void insertionSort(int top, s tag[])
{
	int i, j;
	s tmp;
	for (i = 1; i < top; ++i) {
		tmp = tag[i];
		for (j = i - 1; j >= 0 && strcmp(tag[j].word, tmp.word) > 0 && tag[j].score == tmp.score; --j) tag[j + 1] = tag[j];
		tag[j + 1] = tmp;
	}
}

int main(void)
{
	char tmp[21];
	int N, M, S, top = 0, i, j, k;
	s tag[10000];
	for (i = 0; i < 10000; ++i) tag[i].score = 0;
	scanf("%d", &N);
	for (i = 0; i < N; ++i) {
		scanf("%*d%d%d", &M, &S);
		for (j = 0; j < M; ++j) {
			scanf("%s", tmp);
			for (k = 0; k < top; ++k) {
				if (strcmp(tag[k].word, tmp) == 0) break;
			}
			if (k == top) {
				strcpy(tag[top].word, tmp);
				tag[top].score += S;
				++top;
			}
			else tag[k].score += S;
		}
	}
	qsort(tag, top, sizeof(s), compare);
	insertionSort(top, tag);
	for (i = 0; i < 10 && i < top; ++i) printf("%s %d\n", tag[i].word, tag[i].score);
	return 0;
}
0