这题我用二分,在最后两个测试点WA了,怎么也想不明白,请各位大侠帮忙看看哪里错了
int main(){
boost;
string s;
cin >> s;
int n = s.length();
int l = 1, r = n;
int ans = -1;
while(l <= r){
int m = (l + r) >> 1;
bool ok = false;
for(int i = 0; i <= n - m; ++i){
string tmp = s.substr(i, m);
int c1 = 0, c2 = 0, c3 = 0;
for(int j = 0; j < m; ++j){
if(tmp[j] == 'h') ++c1;
if(tmp[j] == 'i') ++c2;
if(tmp[j] == 'o') ++c3;
}
if(c1 >= 2 && c2 && c3){
if(c1 == 2 && c2 == 1 && c3 == 1)
ans = m;
ok = true;
// break;
}
}
if(ok){
// ans = m;
r = m - 1;
}else{
l = m + 1;
}
}
cout << ans << endl;
return 0;
}
因为只得了80分