include stdio include stdlib include string Пользователь вводит ОДНУ с

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Пользователь вводит ОДНУ строку. Она оканчивается ТОЧКОЙ.
//Введи строку в память (массив динамический). Посчитай
//кол-во слов
using namespace std;
int main()
{
char *a = NULL;
char x = 0;
int count = 0;
char *b = "IamNotLazyAss";
cout << "Word to search: ";
cout << b;
cout << endl << "Now enter a sentence: ";
cin.get(x);
while (x == ' ')
{
cin.get(x);
}
if (x == '.')
return 0;
a = (char* )malloc (sizeof(char));
count++;
a[0] = x; //ввели первый символ
int count1 = 1;
while (x != '.')
{
char prevC = x;
a = (char *) realloc (a, (count1 + 1) * sizeof(char));
cin.get(x);
a[count1] = x;
count1++;
if ((prevC == ' ') && (x != ' ') && (x != '.'))
count ++;
}
cout << "There are " << count << " words." << endl;
cout << "There are " << count1-1 << " symbols." << endl;
unsigned leng;
leng = strlen(b); // количество символов во втором массиве
//cout << leng << endl;
char * p;
int lazyass = 0;
int j = 0;
char *RememberA;//a;
//cout << &RememberA << ' ' << a << endl;
/*while (strstr(RememberA,b) > 0)
{
lazyass++;
RememberA++;
}*/
while ( j < leng )
{
RememberA = strstr(a, b);
if (*RemeberA != NULL)
lazyass++;
cout << RememberA << endl;
a++;
j++;
}
cout << "There are " << lazyass << " not lazy asses." << endl;
free (a);
return 0;
}