#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<string> #include<cstdio> #include<cmath> #include<stack> #include<cstring> #include<functional> #include<queue> #include<set> #include<map> #define LL long long #define lp(s,i,n) for(int i = s;i < n;i++) #define lpd(s,i,n) for(int i = s;i <= n;i++) #define clr(a,b) memset(a,b,sizeof(a)) #define scn(a) scanf("%I64d",&a) #define prf(a) printf("%d\n",a) using namespace std; const int N = 100020; const int MAXE = 20020; const int INF = 0x3f3f3f3f; const double pi = 2 * asin(1); int cnt,pp; int n, m; int a[1000020], b[1000020]; int nex[1000020]; void get_next(string p, int *x) { int i, j; i = 0; j = -1; nex[0] = -1; while (i < p.size()) { if (j == -1 || p[i] == p[j]) { i++; j++; //next[i] = j; if (p[i] != p[j]) nex[i] = j; else nex[i] = nex[j]; //cout << "next[i] = " << j << endl; } else { j = nex[j]; //cout << "i = " << i << " j = " << j << endl; } } } int index_kmp(string p, string x) { int i = -1; int j = -1; int len1 = p.size(); int len2= x.size(); get_next(x, nex); while (i < len1 && j < len2) { if (j == -1 || p[i] == x[j]) { i++; j++; } else { j = nex[j]; //cout << "i = " << i << " j = " << j << endl; } if (j == len2) { cnt++; j =0; } } return cnt; } int main(void) { int t; string a, b; while (cin>>a) { if (a[0] == '#')break; cnt = 0; cin >> b; //cin >> n >> m; //cin >> b >> a; int ans = index_kmp(a, b); cout << ans << endl; } system("pause"); }