結果

問題 No.345 最小チワワ問題
ユーザー ignis_fatuus
提出日時 2016-02-28 22:07:58
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 606 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 57,652 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-25 11:34:09
合計ジャッジ時間 1,426 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>

int find(std::string s,int pos) {
    int count=0, i=pos;
    for(;i<s.size() && count!=2;++i) {
        if(s[i]=='w') ++count;
    }
    if(count==2)
        return i-pos;
    else
        return -1;
}

int main() {
    const char ptn[] = "cww";
    std::string s;std::cin>>s;
    int minimum=200;
    for(int i=0;i<s.size();++i) {
        if(s[i]=='c') {
            int length = find(s,i);
            if(length>0)
                minimum = std::min(length, minimum);
        }
    }
    int ans= (minimum==200) ? -1 : minimum ;
    std::cout << ans << std::endl;
}
0