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
| #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
typedef std::string T_str;
typedef float T_real;
typedef struct stud
{
T_str name;
T_str group;
T_real ball;
} T_stud;
typedef std::vector<T_stud> T_vec;
class students
{
private:
T_vec v;
public:
students(const T_vec &_v): v(_v) {};
friend std::ostream& operator<< (std::ostream& os, T_stud& st);
void show() const
{
std::copy(std::begin(v), std::end(v), std::ostream_iterator<T_stud> (std::cout, "\n"));
};
void sort ()
{
std::sort(std::begin(v), std::end(v), [] (T_stud a, T_stud b) { return a.group < b.group; });
for ( auto f = std::begin(v), l = std::find_if(f, std::end(v),
[&] (T_stud i) { return f->group != i.group; });
f != std::end(v) ; f = l , l = std::find_if
(f, std::end(v), [&] (T_stud i) { return f->group != i.group; }) )
std::sort (f, l, [] (T_stud a, T_stud b) { return a.ball < b.ball; });
};
};
std::ostream& operator<< (std::ostream& os, const T_stud& st)
{
os << "name: " << st.name;
os << "\t group: " << st.group;
os << "\t ball: " << st.ball;
return os;
}
int main()
{
T_vec v = {{"Ivanov", "012", 4.1}, {"Petrov", "011", 2.1}, {"Sidorov", "012", 4.0}};
students univer(v);
univer.show();
std::cout << std::endl;
univer.sort();
univer.show();
std::cout << std::endl;
return 0;
} |