设为首页 加入收藏

TOP

问题一百二十三:统计子串
2014-11-23 22:13:08 来源: 作者: 【 】 浏览:1
Tags:问题 一百二十三 统计

[plain] Description

输入一个字符串str和一个子串s,统计str中子串s的个数。

Input

输入数据有2行,第一行为str,第二行为s,字符串长度不超过128。

Output

输出子串的个数

Sample Input


sdf$$$sdf$$
sdf

Sample Output


2

Description

输入一个字符串str和一个子串s,统计str中子串s的个数。

Input

输入数据有2行,第一行为str,第二行为s,字符串长度不超过128。

Output

输出子串的个数

Sample Input


sdf$$$sdf$$
sdf

Sample Output


2


[plain] #include
#include

int main()
{
int i;
int j;
int l;
int n;
int m;
int count;
int flag;
char a[129];
char b[129];

gets(a);
gets(b);

n=strlen(a);
m=strlen(b);
count=0;

for(i=0; i {
flag=1;
j=0;
if(a[i]==b[j])
{
l=i;
for(j=1; j {
if(b[j]!=a[++l])
{
flag=0;
break;
}
}

if(flag)
{
count++;
}
}

}

printf("%d", count);

return 0;
}

#include
#include

int main()
{
int i;
int j;
int l;
int n;
int m;
int count;
int flag;
char a[129];
char b[129];

gets(a);
gets(b);

n=strlen(a);
m=strlen(b);
count=0;

for(i=0; i {
flag=1;
j=0;
if(a[i]==b[j])
{
l=i;
for(j=1; j {
if(b[j]!=a[++l])
{
flag=0;
break;
}
}

if(flag)
{
count++;
}
}

}

printf("%d", count);

return 0;
}

\

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇问题一百二十四:字符过滤 下一篇问题一百二十六:促销的价格

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: