【搜索入门】搜索字符串
2014-02-25 15:56
316 查看
搜索字符串 | ||
| ||
description | ||
搜索字符串 | ||
input | ||
输入两个字符串a,b(字符串长度不超过1000) | ||
output | ||
输出在a中出现b的次数(每个结果占一行) | ||
sample_input | ||
abcdefsdabcbacbbc abc aabbaabbaabbaa abbaa | ||
sample_output | ||
2 3 |
#include <stdlib.h>
#include <string.h>
#define MAX 1010
int main()
{
char a[MAX],b[MAX];
while(gets(a)!=NULL)
{
gets(b);
int sum=0,i=0,j=0;
int lena,lenb;
lena=strlen(a);
lenb=strlen(b);
while(i<lena)
{
if(a[i]==b[j])
{
i++;
j++;
}
else
{
i=i-j+1;
j=0;
}
if(j>=lenb)
{
sum++;
i=i-j+1;
j=0;
}
}
printf("%d\n",sum);
}
}
相关文章推荐
- 2014马年祝福语大全
- 2014年春节是几月几号 2014春节放假安排时间表
- 2014年数伏是哪天 数伏从什么时候开始
- 2014过年倒计时示例
- 5 Trends a Stylish Bride would love to Know in 201
- 北大—1006——Biorhythms
- 2013年阿里巴巴测试开发类笔试题 9-22号晚上考的
- 9-24号大众点评技术研发笔试题
- 9月28日 南京 百度测试开发工程师 笔试题
- 2014-1-23 First Day Auto Transport
- 2014-1-25 Plan A For Transport
- hdu 1423 动态规划
- hdu2544 dijkstra最短路径问题
- hdu1048map解法和一般解法
- POJ1657-Distance on Chessboard
- 【数学基础】快速幂
- 【数学基础】取石子游戏(一)
- 成功当选2014年度MVP
- 2014软考软件设计师考前辅导:异常的使用心得
- Coder-Strike 2014 - Round 2 B. Spyke Chatting