-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
164 lines (154 loc) · 3.3 KB
/
Copy pathmain.cpp
File metadata and controls
164 lines (154 loc) · 3.3 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <ncurses.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
bool isWordSuit(int *last_word, const int last_word_length, int *current_word, const int current_word_length, const int max_len)
{
if (current_word_length != max_len)
{
return false;
}
if (last_word_length != current_word_length)
{
return true;
}
if (current_word_length == last_word_length && current_word_length == max_len)
{
for (size_t i = 0; i < last_word_length; i++)
{
if (last_word[i] != current_word[i])
{
return true;
}
}
}
return false;
}
int main()
{
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
int size_of_console = w.ws_col;
initscr();
noecho();
int c;
int max_lenght = 0;
int current_length = 0;
int *last_word = new int[200];
int *current_word = new int[200];
int last_word_lenght;
int n = -1;
int *arr = new int[400];
int kn = 0, qn = 0;
int j = 0;
while ((c = getch()) != '.')
{
if ((c > 96 && c < 123) || (c == 127) || (c == 32))
{
if (c > 96 && c < 123 || (c == 32))
{
echochar(c);
n++;
qn = n % size_of_console;
kn = n / size_of_console;
arr[n] = c;
}
if (c == 127 && n != -1)
{
arr[n] = -1;
move(kn, qn);
echochar(' ');
move(kn, qn);
n--;
qn = n % size_of_console;
kn = n / size_of_console;
}
}
}
echochar(c);
echochar('\n');
n++;
//clearing all whitespaces at the end;
int nCurrent = n;
while (arr[nCurrent - 1] == 32)
{
nCurrent--;
}
n = nCurrent;
n++;
arr[n - 1] = '.';
int z = 0;
for (z = n - 2; z >= 0; z--)
{
if (arr[z] == ' ')
{
break;
}
if (arr[z] != ' ')
{
last_word_lenght++;
}
else
{
break;
}
}
int qq = 0;
for (int i = z + 1; i < n - 1; i++)
{
last_word[qq] = arr[i];
qq++;
}
for (size_t i = 0; i < n - last_word_lenght; i++)
{
if (arr[i] == 32)
{
if (j > max_lenght)
{
max_lenght = j;
}
j = 0;
}
else
{
j++;
}
}
if (j > max_lenght)
{
max_lenght = j;
}
if (max_lenght < last_word_lenght)
{
max_lenght = last_word_lenght;
}
j = 0;
for (size_t i = 0; i < n - last_word_lenght; i++)
{
if (arr[i] == 32)
{
if (isWordSuit(last_word, last_word_lenght, current_word, j, max_lenght))
{
for (size_t q = 0; q < j; q++)
{
echochar(current_word[q]);
}
echochar(' ');
}
j = 0;
}
else
{
current_word[j] = arr[i];
j++;
}
}
while (getch() != 'q')
{
}
delete[] arr;
delete[] last_word;
delete[] current_word;
endwin();
return 0;
}