結果

問題 No.345 最小チワワ問題
ユーザー E31415926E31415926
提出日時 2016-03-30 11:23:59
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 450 bytes
コンパイル時間 505 ms
コンパイル使用メモリ 55,108 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 11:41:26
合計ジャッジ時間 1,423 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>

using namespace std;

int main()
{
	string s;
	int min = 101, i, j, n, flags;
	cin >> s;
	n = s.length();
	for (i = 0; i < n; i++) {
		if (s[i] == 'c') {
			flags = 0;
			for (j = i; flags < 2 && j < n; j++) {
				if (s[j] == 'w') {
					flags++;
				}
			}
			if (flags == 2 && j - i < min) {
				min = j - i;
			}
		}
	}
	if (min == 101) {
		cout << -1 << endl;
	}
	else {
		cout << min << endl;
	}
	return 0;
}
0