【王道机试】-字符串匹配-string matching-上海交通大学

熟悉find函数的用法

#include <iostream>
#include <string>
using namespace std;
int main(){
    string t;
    string p;
    cin>>t>>p;
    int k=0;
    int count=0;
    k=t.find(p);
    while(k!=-1){ 
        count++;
        k=t.find(p,k+1);      
    }
    cout<<count<<endl;
}

猜你喜欢

转载自blog.csdn.net/qq_39328436/article/details/114631601