forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
39 lines (35 loc) · 881 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Authored by : tony9402
// Co-authored by : -
// Link : http://boj.kr/542de8e26b06406182f52af66cda1fc8
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
string s; cin >> s;
const string DB = "quack";
int n = s.size();
vector<int> used(n), cnt(n);
bool result = true;
for(int i=0;i<n;i++){
if(s[i] != 'q')continue;
int R = i, idx = 0;
while(idx < 5 && R < n){
if(used[R] == 0 && s[R] == DB[idx]){
used[R] = 1;
idx++;
}
R++;
}
if(idx != 5) result = false;
for(int j=i;j<R;j++) cnt[j]++;
}
int ans = 0;
for(int i=0;i<n;i++){
ans = max(ans, cnt[i]);
if(cnt[i] == 0)result = false;
}
if(result)cout << ans;
else cout << -1;
return 0;
}