結果

問題 No.345 最小チワワ問題
ユーザー くれちー
提出日時 2016-09-09 20:23:21
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 21,632 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-25 11:52:50
合計ジャッジ時間 1,133 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:8:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf("%s", s);
      |         ^~~~~~~~~~~~~~

ソースコード

diff #

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

int main() {
	char s[101];
	int l = 101, i, j, k;

	scanf("%s", s);

	if (strlen(s) < 3) {
		printf("-1\n");
		return 0;
	}

	for (i = 0; i < strlen(s) - 2; i++) {
		if (s[i] == 'c') {
			for (j = i + 1; j < strlen(s) - 1; j++) {
				if (s[j] == 'w') {
					for (k = j + 1; k < strlen(s); k++) {
						if (s[k] == 'w') {
							if (k - i + 1 < l) l = k - i + 1;
							break;
						}
					}
				}
			}
		}
	}

	if (l == 101) printf("-1\n");
	else printf("%d\n", l);

	return 0;
}
0