【杭电100题】2087 剪花布条

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2087

string a;
cin>>a;
这里的cin是遇到空格停止的。

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string a,b;
    int cnt;
    while(cin>>a && a!="#")
    {
        cin>>b;

        cnt=0;
        int tmp=a.find(b,0);
        while(tmp!=-1)
        {
            cnt++;
            tmp=a.find(b, tmp+b.length());
        }
        cout<<cnt<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41727666/article/details/88429221