#include <iostream.h>
#include <stdio.h>
#include <string.h>
int countsubs(char p[], char s[], int lp, int ls)
{
int i,j,k,count=0;
for(i=0;i<=lp-ls;i++)
{
for(k=0,j=i;k<ls&&s[k]==p[j];k++,j++);
if(k==ls) count++;
}
return count;
}
void main()
{
char p[]="abcdabcdabababcdab";
char s[]="ab";
int lp=strlen(p);
int ls=strlen(s);
int subs=countsubs(p,s,lp,ls);
cout << subs << endl;
}
posted on 2006-09-24 19:03
创建更好的解决方案 阅读(580)
评论(0) 编辑 收藏 引用