zoj 3643 Keep Deleting 【桟】

题意:给出两个字符串,a和b,在b中删除a串,删除多少次不能在删除了。

#include<stdio.h>
#include<string.h>

char b[520000],a[2000],st[520000];

int main()
{
	while(scanf("%s %s", a, b) != EOF) {
		int ans = 0;
		int tp = 1;
		int len = strlen(a);
		for(int i = 0; b[i]; i++) {
			st[tp-1] = b[i];
			if(tp >= len) {
				st[tp] = 0;
				if(strcmp(st+tp-len, a) == 0) {
					tp -= len;
					ans++;
				}
			}
			tp++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

 

posted @ 2012-08-26 22:37  小猴子、  阅读(288)  评论(0编辑  收藏  举报