-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathchar_changer.cpp
More file actions
54 lines (47 loc) · 1.42 KB
/
char_changer.cpp
File metadata and controls
54 lines (47 loc) · 1.42 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
#include <cstddef>
#include <cctype>
size_t CharChanger(char array[], size_t size, char delimiter = ' ') {
//Массив для подстановки кол-ва повторений
char intToChar[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
size_t i = 0;
size_t j = 1;
size_t str_end = 0;
int reps = 1; // кол-во повторений символа
while (j < size) {
if (array[i] == array[j]) {
++reps;
++j;
continue;
}
array[str_end] = array[i];
if (reps != 1 && array[i] != ' ') {
array[str_end+1] = reps < 10 ? intToChar[reps] : intToChar[0];
}
if (char c = array[str_end]; std::isalpha(c) && std::islower(c)) {
array[str_end] = std::toupper(c);
}
else if (array[str_end] == ' ') {
array[str_end] = delimiter;
++str_end;
i = j++;
reps = 1;
continue;
}
else if (std::isdigit(array[str_end])) {
array[str_end] = '*';
}
else if (!(std::isalpha(array[str_end]))) {
array[str_end] = '_';
}
if (reps == 1) {
++str_end;
}
else {
str_end+= 2;
reps = 1;
}
i = j++;
}
array[str_end] = '\0';
return str_end;
}