-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (63 loc) · 2.5 KB
/
Copy pathmain.cpp
File metadata and controls
78 lines (63 loc) · 2.5 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
#include <iostream>
#include <string>
#include "list.cpp"
using namespace std;
int main() {
List<string> studentList; // Ñïèñîê äëÿ õðàíåíèÿ ñòóäåíòîâ â ôîðìàòå "<íîìåð ãðóïïû> <ôàìèëèÿ>"
// Ââîä äàííûõ (ïðèìåð)
studentList.pushback("320 Kozlov");
studentList.pushback("324 Petrov");
studentList.pushback("322 Pavlov");
studentList.pushback("325 Morozov");
studentList.pushback("321 Dorofeev");
studentList.pushback("323 Smirnov");
studentList.pushback("322 Bogdanov");
studentList.pushback("324 Sokolov");
studentList.pushback("320 Medvedev");
studentList.pushback("321 Sidorov");
studentList.pushback("323 Novikov");
studentList.pushback("325 Popov");
studentList.pushback("322 Ivanov");
studentList.pushback("324 Kuznetsov");
studentList.pushback("323 Fedorov");
studentList.pushback("320 Vinogradov");
studentList.pushback("321 Lebedev");
studentList.pushback("325 Volkov");
List<int> groupNumbers; // cïèñîê íîìåðîâ ãðóïï
List<string>* groups = nullptr; // ìàññèâ ñïèñêîâ ñòóäåíòîâ ïî ãðóïïàì
for (int i = 0; i < studentList.getSize(); i++) {
// íîìåð ãðóïïû
int groupNumber = stoi(studentList[i].substr(0, studentList[i].find(' ')));
// äîáàâëÿåì íîìåð ãðóïïû â ñïèñîê, åñëè åãî íåò
if (!groupNumbers.is_in(groupNumber)) {
groupNumbers.pushback(groupNumber);
}
}
// ìàññèâ ñïèñêîâ ïî êîëè÷åñòâó óíèêàëüíûõ ãðóïï
int uniqueGroupCount = groupNumbers.getSize();
groups = new List<string>[uniqueGroupCount];
//ñïèñêè ñòóäåíòîâ ïî èõ ãðóïïàì
for (int i = 0; i < studentList.getSize(); i++) {
string student = studentList[i];
// èçâëåêàåì íîìåð ãðóïïû ñòóäåíòà
int groupNumber = stoi(student.substr(0, student.find(' ')));
// èíäåêñ ñïèñêà, ñîîòâåòñòâóþùåãî äàííîé ãðóïïå
for (int j = 0; j < uniqueGroupCount; j++) {
if (groupNumbers[j] == groupNumber) { // åñëè íîìåð ãðóïïû ñîâïàë, äîáàâëÿåì ñòóäåíòà â ñïèñîê ãðóïïû
groups[j].pushback(student);
break; // ïðåðûâàåì öèêë, åñëè ãðóïïà íàéäåíà
}
}
}
// âûâîä ñïèñêîâ
for (int i = 0; i < uniqueGroupCount; i++) {
cout << "Group " << groupNumbers[i] << ":" << endl;
for (int j = 0; j < groups[i].getSize(); j++) {
cout << groups[i][j].substr(groups[i][j].find(' ') + 1) << endl;
}
cout << endl;
}
// Îñâîáîæäàåì ïàìÿòü
delete[] groups;
return 0;
}