結果

問題 No.205 マージして辞書順最小
ユーザー FF256grhyFF256grhy
提出日時 2015-05-09 01:19:48
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 857 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 24,752 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 09:13:05
合計ジャッジ時間 1,277 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 4 ms
4,384 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 0 ms
4,380 KB
testcase_15 AC 0 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 0 ms
4,384 KB
testcase_18 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘get_min’:
main.c:36:7: warning: implicit declaration of function ‘compare’; did you mean ‘comapre’? [-Wimplicit-function-declaration]
   if( compare(i, p[i], min, p[min]) ) { min = i; }
       ^~~~~~~
       comapre

ソースコード

diff #

#include <stdio.h>

int get_min();
int comapre(int, int, int, int);

int n;
char s[51][51];
int p[51];
char answer[2501];

int main(void) {
	scanf("%d", &n);
	int i;
	for(i = 0; i < n; i++) {
		scanf("%s", s[i]);
	}
	s[n][0] = 'z' + 1;
	
	int cnt = 0;
	while(1) {
		int m = get_min();
		if(m == n) { break; }
		answer[cnt] = s[m][ p[m] ];
		cnt++;
		p[m]++;
	}
	answer[cnt] = '\0';
	printf("%s\n", answer);
	return 0;
}

int get_min() {
	int min = n;
	int i;
	for(i = 0; i < n; i++) {
		if( compare(i, p[i], min, p[min]) ) { min = i; }
	}
	return min;
}

int compare(int a, int pa, int b, int pb) { // return (a < b);
	if(s[a][pa] == '\0') { return 0; }
	if(s[b][pb] == '\0') { return 1; } // '\0' が一番大きいと解釈する
	if(s[a][pa] != s[b][pb]) { return (s[a][pa] < s[b][pb]); } // '\0' < 'a' を利用
	return compare(a, pa + 1, b, pb + 1);
}
0