C++字符串substr在母字符串str中出现的次数
发布网友
发布时间:2023-07-15 08:34
我来回答
共2个回答
热心网友
时间:2024-12-05 22:45
(1)
int func(char *str, char *substr)
{
int count = 0;
char *cur = substr;
while (*str != '\0')
{
if (*str == *cur)
{
while (*cur != '\0')
{
if (*cur++ == *str++)
continue;
else
break;
}
if (*cur == '\0')
count++;
cur = substr;
}
else
{
str++;
}
}
return count;
}
热心网友
时间:2024-12-05 22:46
(1)
int
func(char
*str,
char
*substr)
{
int
count
=
0;
char
*cur
=
substr;
while
(*str
!=
'\0')
{
if
(*str
==
*cur)
{
while
(*cur
!=
'\0')
{
if
(*cur++
==
*str++)
continue;
else
break;
}
if
(*cur
==
'\0')
count++;
cur
=
substr;
}
else
{
str++;
}
}
return
count;
}