您的位置:首页 > 其它

HDOJ 2087 剪花布条----strstr函数

2015-07-22 19:06 274 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2087



/*

strstr(str1,str2)是一种函数,从字符串str1中查找是否有符串str2,

如果有,从str1中的str2位置起,返回str1的指针,如果没有,返回null。

*/

#include<stdio.h>

#include<string.h>

#include<math.h>

#include<ctype.h>

#include<stdlib.h>

#define N 1010

char a
,b
;

int main()

{

int t;

int str;

char *p;

while(scanf("%s%s",a,b)&&a[0]!='#')//必须用scanf,而不能用gets()

{

p=a;

t=0;

str=strlen(b);

while((p=strstr(p,b))!=NULL)//strstr(p,b)

{

t++;

p+=str;//从a中b的位置返回a的指针,p+strlen(b)进入第一个b出现之后的位置进行判断

}

printf("%d\n",t);

}

return 0;

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: