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;
}
/*
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;
}
相关文章推荐
- Android blueZ HCI(一个):hciconfig实施和经常使用
- NOJ1064快速排序(基础的快速排序,以及动态数组的使用)
- JAVA之堆内存和栈内存的区别
- 透视投影
- Android开发初学者问题
- 实用中时间戳与日期互转
- HDOJ 2027 单词数
- HASH Partitioning--转载
- 数据类型转换 和 break,continue语句
- sort
- linux cpu 信息查看
- 浅谈Java中的System.gc()的工作原理
- C# 基本知识纪录
- 【leetcode】 26. Remove Duplicates from Sorted Array
- 中文版iTween帮助文档、参数解析
- [Leetcode]-Best Time to Buy and Sell Stock
- 苹果iOS苹果公司的手机用户都有权索赔
- 移动效果向导,旋转效果
- 为什么咱们坚持写博客,开源自己的项目?
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener问题解决