hiho一下 第243周 1485 hiho字符串

尺取做法,注意这题是恰好为2个h,1个i,1个o。

#include<bits/stdc++.h>
using namespace std;
string Str;

int main(){
    while(cin>>Str){
        int l= 0,r=-1,n = Str.size(),ans = -1;
        map<char,int> cnt;
        for(;;){
          while(r<n&&!(cnt['h']>=2&&cnt['i']>=1&&cnt['o']>=1)){
               r++;
               if(r<n){
                    cnt[Str[r]]++;
               }
          }
          if(r==n) break;
          if(cnt['h']==2&&cnt['i']==1&&cnt['o']==1){
               if(ans==-1||r-l+1<ans) ans = r-l+1;
          }
          cnt[Str[l++]]--;
        }
        cout<<ans<<endl;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值