题目:
heo/source/_posts/洛谷-题单-字符串-代码/10.单词覆盖还原.md
代码:

include

include

using namespace std;

int main(){
int numboy = 0,numgirl = 0;
string s;
cin>>s;

for(int i = 0; i<s.size();i++){
    //cout<<"i-->"<<i<<" ";
    if(s[i] == 'b'){
        if(s[i + 1] == 'o'){
            if(s[i + 2] == 'y'){
                numboy++;
                i = i+2;
            //    cout<<endl<<"boy"<<endl;
            }
            else{
                numboy++;
                i = i+1;
            //    cout<<endl<<"bo"<<endl;
            }
        }
        else{
            //i++;
            numboy++;
        //    cout<<endl<<"b"<<endl;
        }
    }

    else if(s[i] == 'o'){
        if(s[i + 1] == 'y'){
            numboy++;
            i = i+1;    
            //cout<<endl<<"oy"<<endl;
        }
        else{
            //i++;
            numboy++;
            //cout<<endl<<"o"<<endl;
        }
    }

    else if(s[i] == 'y'){
        //cout<<endl<<i;
        //i++;
        numboy++;
        //cout<<endl<<"y"<<endl;
    }

    else if(s[i] == 'g'){
        if(s[i + 1] == 'i'){
            if(s[i + 2] == 'r'){
                if(s[i + 3] == 'l'){
                    numgirl++;
                    i = i+3;
                    //cout<<endl<<"girl"<<endl;
                    //cout<<endl<<i;
                }
                else{
                    numgirl++;
                    i = i+2;
                //    cout<<endl<<"gir"<<endl;
                }
            }
            else{
                numgirl++;
                i = i+1;
                //cout<<endl<<"gi"<<endl;
            }
        }
        else{
            numgirl++;
            //cout<<endl<<"g"<<endl;
        }
    }

    else if(s[i] == 'i'){
        if(s[i + 1] == 'r'){
            if(s[i + 2] == 'l'){
                numgirl++;
                i = i+2;    
                //cout<<endl<<"irl"<<endl;
            }
            else{
                numgirl++;
                i = i+1;    
                //cout<<"ir"<<endl;
            }
        }else{
            numgirl++;    
        //    cout<<endl<<"i"<<endl;
        }
    }

    else if(s[i] == 'r'){
        if(s[i + 1] == 'l'){
            numgirl++;
            i = i+1;    
            //cout<<endl<<"rl"<<endl;
        }
        else{
            numgirl++;
            //cout<<endl<<"r"<<endl;
        }
    }

    else if(s[i] == 'l'){
        //i++;
        numgirl++;
        //cout<<endl<<"l"<<endl;
    }

}
cout<<numboy<<endl<<numgirl;

return 0;

}
错误:if里面不能用break;