結果

問題 No.345 最小チワワ問題
ユーザー kapokapo
提出日時 2016-05-03 18:00:12
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 372 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 21,248 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-25 11:43:44
合計ジャッジ時間 1,016 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:17: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[101]’ [-Wformat=]
    7 |         scanf("%s", &s);
      |                ~^   ~~
      |                 |   |
      |                 |   char (*)[101]
      |                 char *
main.c:9:26: warning: comparison between pointer and integer
    9 |         for( i = 0; s[i] != NULL; i++) {
      |                          ^~
main.c:12:44: warning: comparison between pointer and integer
   12 |                         for( j = i+1; s[j] != NULL && c != 2; j++) {
      |                                            ^~
main.c:7:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%s", &s);
      |         ^~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(void)
{
	int i, j, m = 100, c;
	char s[101] = {};
	scanf("%s", &s);

	for( i = 0; s[i] != NULL; i++) {
		if(s[i] == 'c') {
			c = 0;
			for( j = i+1; s[j] != NULL && c != 2; j++) {
				if( s[j] == 'w' ) c++;
				if( c == 2 && j-i+1 < m) m = j-i+1;
			}
		}
	}
	if( m == 100 ) {
		printf("-1\n");
		return 0;
	}
	printf("%d\n", m);
	return 0;
}
0