题解 | #String Matching#
String Matching
https://www.nowcoder.com/practice/00438b0bc9384ceeb65613346b42e88a
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
int main(){
string S1 ;
string S2 ;
cin >> S1 >> S2;
int len1 = S1.length();
int len2 = S2.length();
int pos =0;
for(int i = 0 ; i < len1;++i){
int pos2 = S1.find(S2,i);
if(pos2 != -1){
++pos;
i=pos2;
continue;
}
}
printf("%d\n",pos);
}
查看3道真题和解析