hdu 2087 剪花布條 strstr使用 或者 KMP

strstr
語法:

#include <string.h>
char *strstr( const char *str1, const char *str2 );

功能:函數返回一個指針,它指向字符串str2 首次出現於字符串str1中的位置,如果沒有找到,返回NULL。


#include <stdio.h>
#include <string.h>
int main()
{
    char text[1005],pat[1005],*p;
    while(scanf("%s",text)&&text[0]!='#')
    {
        scanf("%s",pat);
        int l=strlen(pat),cnt=0;
        for(p=text;p=strstr(p,pat);p+=l) cnt++;
        printf("%d\n",cnt);
    }
    return 0;
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章