Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- #include <vector>
- using namespace std;
- struct student
- {
- string f, i, o;
- int year;
- int m[5];
- bool operator > (student s)
- {
- if (f != s.f) return (f > s.f);
- else if (i != s.i) return (i > s.i);
- else return (o > s.o);
- }
- };
- class Base
- {
- int group;
- vector <student> st;
- public:
- Base (int g) : group(g) {}
- void push (student s) { st.push_back(s); }
- void bubble_sort() //сортировка пузырьком
- {
- for (int i = 0; i < st.size(); ++i)
- for (int j = 1; j < st.size() - i; ++j)
- if (st[j - 1] > st[j]) swap(st[j - 1], st[j]);
- }
- void insertion_sort() //сортировка вставками
- {
- for (int i = 0; i < st.size(); ++i)
- {
- int j = i;
- while (j > 0 && st[j - 1] > st[j]) { swap(st[j], st[j - 1]); --j; }
- }
- }
- void selection_sort() //сортировка посредством выбора
- {
- for (int i = 0; i < st.size(); ++i)
- {
- int it = i;
- for (int j = i + 1; j < st.size(); ++j)
- if (st[it] > st[j]) it = j;
- swap(st[i], st[it]);
- }
- }
- void print(ostream &is)
- {
- is << left;
- is << "Group: " << group << '\n';
- is << setw(15) << "Familiya" << setw(10) << "Imya" << setw(15) << "Otchestvo" << setw(5) << "Year" << "Marks\n";
- for (int i = 0; i < st.size(); ++i)
- is << setw(15) << st[i].f << setw(10) << st[i].i << setw(15) << st[i].o << setw(5) << st[i].year << st[i].m[0] << " " << st[i].m[1] << " " << st[i].m[2] << " " << st[i].m[3] << " " << st[i].m[4] << '\n';
- }
- };
- int main()
- {
- ifstream fin ("input.txt");
- ofstream fbubble ("bubble.txt");
- ofstream finsertion ("insertion.txt");
- ofstream fselection ("selection.txt");
- int g; fin >> g; //номер группы
- Base bubbleBase(g);
- while (fin.peek() != EOF)
- {
- student s;
- fin >> s.f >> s.i >> s.o >> s.year >> s.m[0] >> s.m[1] >> s.m[2] >> s.m[3] >> s.m[4];
- bubbleBase.push(s);
- }
- Base insertionBase = bubbleBase;
- Base selectionBase = bubbleBase;
- bubbleBase.bubble_sort();
- bubbleBase.print(fbubble);
- insertionBase.insertion_sort();
- insertionBase.print(finsertion);
- selectionBase.selection_sort();
- selectionBase.print(fselection);
- bubbleBase.print(cout);
- fin.close();
- fbubble.close();
- finsertion.close();
- fselection.close();
- return 0;
- }
- //input.txt
- 211
- Ivanov Ivan Ivanovich 2001 2 2 3 4 5
- Ivanova Marya Ivanovna 2000 3 3 4 3 4
- Ivanov Ivan Ivanovich 2003 4 3 3 4 3
- Ivanov Petya Petrovich 2003 5 4 3 4 4
- Abramov Mark Pavlovich 2000 3 2 5 2 3
- Akimova Victoria Konstantinovna 2002 4 3 3 2 3
- Alekseeva Anastasia Nikolaevna 2000 4 3 2 3 3
- Andreev Kirill Leonidovich 2003 4 3 4 4 2
- Andreev Andrey Egorovich 2000 4 3 3 3 4
- Kuzmina Ksenia Tikhonovna 2002 2 4 2 3 5
- //II 18 сортировка кучей, быстрая сортировка, добавить sort
Add Comment
Please, Sign In to add comment