HDU-2087 剪花布条

HDU-2087 剪花布条
HDU-2087 剪花布条

代码

#include <iostream>

using namespace std;

int main() {

    string s1;
    cin>>s1;
    while(s1.compare("#")){
        string s2;
        cin>>s2;
        int count = 0;
        while(s1.find(s2)!=-1){
            int pos = s1.find(s2);
            s1 = s1.substr(pos+s2.length());
            count++;
        }
        cout<<count<<endl;
        cin>>s1;
    } 

    return 0;
}

注解

1、常用的字符串处理方法:compare,find,substr方法

结果

HDU-2087 剪花布条