只要看到zoj,就什么题都不会做了。。。
这个题搞了半天KMP,TLE了还是。
比赛结束有人讲了一种方法,用栈去模拟,把b串中的元素一个个入栈,遇到和a相等的就把栈顶出栈。写了几行,过了。
叹水平之差兮……
/*
* Author: stormdpzh
* Created Time: 2012/8/26 19:32:30
* File Name: k.cpp
*/
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <functional>
#define sz(v) ((int)(v).size())
#define rep(i, n) for(int i = 0; i < n; i++)
#define repf(i, a, b) for(int i = a; i <= b; i++)
#define repd(i, a, b) for(int i = a; i >= b; i--)
#define out(n) printf("%d\n", n)
#define mset(a, b) memset(a, b, sizeof(a))
#define wh(n) while(1 == scanf("%d", &n))
#define whz(n) while(1 == scanf("%d", &n) && n != 0)
#define lint long long
using namespace std;
const int INF = 1 << 30;
const int MaxN = 512005;
const int MaxM = 300;
char b[ MaxN ];
char a[ MaxM ];
int len;
int len2;
char stk[ MaxN ];
int gao()
{
int top = 0;
int i = 0;
int cnt = 0;
while( i < len ) {
stk[ top++ ] = b[ i ];
stk[ top ] = '\0';
if( top >= len2 && strcmp( &stk[ top - len2 ], a ) == 0 ) {
cnt++;
top = top - len2;
}
i++;
}
return cnt;
}
int main()
{
while( 1 == scanf( "%s", a ) ) {
scanf( "%s", b );
len = strlen( b );
len2 = strlen( a );
out( gao() );
}
return 0;
}