Входное слово
1.Не содержит пробелов.
2.Меньше 15 символов.
Сохраняйте это
1.Case чувствительный
2. НЕ используйте 'string.h'.
3. Разрешен только 'stdio.h'.
#include<stdio.h>
int search(const char* str1, const char* str2)
int main(void)
{
char input[15];
char string1[400] = " Pinot noir is a red wine grape variety of the species Vitisvinifera. The name may also refer to wines created predominantly from Pinot noir grapes. The name is derived from the French words for pine and black. The word pine alludes to the grape variety having tightly clustered, pine cone-shaped bunches of fruit.[1].";
char string2[400] = " Metallica is an American heavy metal band. The band was formed in 1981 in Los Angeles by vocalist/guitarist James Hetfield and drummer Lars Ulrich, and has been based in San Francisco for most of its career.[1][2] The band's fast tempos, instrumentals and aggressive musicianship made them one of the founding big four bands of thrash metal, alongside Megadeth, Anthrax and Slayer.";
printf("string1: %s\n\n", string1);
printf("string2: %s\n\n", string2);
printf("Enter a word to count:");
scanf("%s", input);
printf("'%s' is found %d times in the string1.\n", input, search(input, string1));
printf("'%s' is found %d times in the string2.\n", input, search(input, string2));
return 0;
}
int mystrlen(const char* str)
{
int i = 0;
while (*str != '\0') {
*(str++);
i++;
}
return i;
}
int search(const char* str1, const char* str2)
{
int result = 0;
int len = mystrlen(str1);
while (*str2 != '\0') {
if (*str2 == *str1) {
while (*str1 != '\0') {
if (*(s1++) != *(s2++))
result = result * 1;
}
if (*(str2--) != ' ' || *str2 + len != ' ')
result = result * 1;
else if (*str2 + len == '.' || *str2 + len == ',')
result++;
result++;
}
*(str2++);
}
return result;
}
ПРИМЕР
string1: "Пино нуар - это сорт красного вина сорта Vitisvinifera. Название может также относиться к винам, созданным преимущественно из винограда сорта Пино Нуар. Название происходит от французских слов" сосна и черный ". . Слово сосна намекает на сорт винограда, имеющий плотные гроздья плодовых сосновых шишек. [1]. ";
string2:" Metallica - американская хэви-металлическая группа. Группа была образована в 1981 году. в Лос-Анджелесе вокалистом / гитаристом Джеймсом Хетфилдом и барабанщиком Ларсом Ульрихом, и большую часть своей карьеры он живет в Сан-Франциско. [1] [2] Быстрые темпы группы, инструментальное звучание и агрессивная музыкальность сделали их одной из основателей большой четверки. полосы из металла sh, рядом с М egadeth, Anthrax and Slayer. ";
Введите слово для подсчета: is
'is' найдено 2 раза в строке 1.
'is' найдено 1 раз в строке 2.