Keep Deleting

 转载请注明出处,谢谢。http://www.cnblogs.com/acmer-roney/---by Roney

题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3643

 

题解:栈模拟

AC代码:

View Code
 1 #include<stdio.h>
 2  #include<string.h>
 3  char a[300],b[520000],flag[520000];
 4  int main()
 5  {
 6      int len,top,ans,i;
 7      while(scanf("%s %s",a,b)!=EOF){
 8          ans=0,top=1;
 9          len=strlen(a);
10          for(i=0;b[i];i++){
11              flag[top-1]=b[i];
12              if(top>=len){
13                  if(!strncmp(flag+top-len,a,len)){
14                      top-=len;
15                      ans++;
16                  }
17              }
18              top++;
19          }
20          printf("%d\n",ans);
21      }
22      return 0;
23  }

 

 

posted on 2012-09-04 17:10  Acmer_Roney  阅读(185)  评论(0)    收藏  举报

导航