// No.345 最小チワワ問題 // https://yukicoder.me/problems/no/345 // using namespace std; #include #include long solve(string &S); int main() { string S; cin >> S; long ans = solve(S); cout << ans << endl; } long solve(string &S) { const long NOT_FOUND = 9999999; long min_size = NOT_FOUND; regex rx(R"(c.*w.*w)"); sregex_iterator it(S.begin(), S.end(), rx); sregex_iterator end; while (it != end) { if (it->str().size() < min_size) min_size = it->str().size(); it++; } if (min_size == NOT_FOUND) return -1; return min_size; }