-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (72 loc) · 1.66 KB
/
main.cpp
File metadata and controls
85 lines (72 loc) · 1.66 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
#include <iostream>
#include "String.h"
void sort(String** mass, int size);
bool repeatitions(String** mass, int size);
bool equalBegin(String** mass, int size, String& search);
int main() {
const int CSEARCH = 5;
char csearch[CSEARCH] = { "abcd" };
String search(csearch);
int size = 5;
std::cout << "Enter 5 strings: \n";
char* buff = new char[1000];
String** string = new String * [size];
for (int i = 0; i < size; i++) {
std::cin >> buff;
string[i] = new String(buff);
}
sort(string, size);
std::cout << "\nThe result:\n";
for (int i = 0; i < size; i++) {
std::cout << *(string[i]) << '\n';
}
if (repeatitions(string, size)) {
std::cout << "There are repeatitions in the string \n";
}
else {
std::cout << "There are no repeatitions in the string \n";
}
if (equalBegin(string, size, search)) {
std::cout << "There are strings starting from "<< search<< '\n';
}
else {
std::cout << "There are no strings starting from " << search << '\n';
}
delete[] string;
return 0;
}
void sort(String** mass, int size) {
int ind = 0;
for (int i = 0; i < size - 1; i++) {
ind = 0;
String* mx = new String;
for (int j = i; j < size; j++) {
if (*mx < *mass[j]) {
mx = mass[j];
ind = j;
}
}
if (ind != 0) {
mass[ind] = mass[i];
mass[i] = mx;
}
}
}
bool repeatitions(String** mass, int size) {
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
if (*(mass[i]) == *(mass[j])) {
return true;
}
}
}
return false;
}
bool equalBegin(String** mass, int size, String& search) {
for (int i = 0; i < size; i++) {
if (mass[i]->find(search, 0) == 0) {
return true;
}
}
return false;
}