标签:
#include <stdio.h> #include <string.h> void main() { while(1) { char input1[1000] = {‘\0‘}; char input2[1000] = {‘\0‘}; int count = 0; scanf("%s", &input1); int len1 = (int)strlen(input1); if(input1[0] == ‘#‘) return; scanf("%s", &input2); int len2 = (int)strlen(input2); //对input1中的每len2个字符进行遍历 for(int i = 0; i < len1;) { char tempBuf[1000] = {‘\0‘}; //在input1中取得len2个连续字符 for(int j = 0; j < len2; j++) { if((i + j) < len1) tempBuf[j] = input1[i + j]; else break; } //比较 if(strcmp(tempBuf, input2) == 0) { count++; i += len2; } else i++; } printf("%d\n", count); } }
标签:
原文地址:http://www.cnblogs.com/mrethan/p/4637684.html