0分超时求调
查看原帖
0分超时求调
1420919
awdfkewd楼主2024/8/21 17:32

自己调了很久,一直超时

#include<iostream>
#include<string>
using namespace std;
string strs;
int i=0,cnt=0,temp;
int main(){
    cin>>strs;
    while(i!=string::npos){
        temp=(int)strs.find("friend",i);
        if(i==string::npos){
            break;
        }
        if(i==0){
            i=temp;
        }else if(temp-i<=2){
            i=temp;
            continue;
        }
        cnt++;
    }
    cout<<cnt;
}
2024/8/21 17:32
加载中...