标签:sam bcb span fine sample problems i++ desc input
搜索字符串
输入两个字符串a,b(字符串长度不超过1000)
输出在a中出现b的次数(每个结果占一行)
abcdefsdabcbacbbc abc aabbaabbaabbaa abbaa
2 3
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 #define MAX 1010 6 7 int main() 8 { 9 char a[MAX],b[MAX]; 10 while(gets(a)!=NULL) 11 { 12 gets(b); 13 int sum=0,i=0,j=0; 14 int lena,lenb; 15 lena=strlen(a); 16 lenb=strlen(b); 17 while(i<lena) 18 { 19 if(a[i]==b[j]) 20 { 21 i++; 22 j++; 23 } 24 else 25 { 26 i=i-j+1; 27 j=0; 28 } 29 if(j>=lenb) 30 { 31 sum++; 32 i=i-j+1; 33 j=0; 34 } 35 } 36 printf("%d\n",sum); 37 } 38 }
标签:sam bcb span fine sample problems i++ desc input
原文地址:https://www.cnblogs.com/twomeng/p/9475944.html