結果

問題 No.205 マージして辞書順最小
ユーザー FF256grhyFF256grhy
提出日時 2015-05-09 00:51:20
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 24,744 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-19 09:09:44
合計ジャッジ時間 1,558 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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