Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stdio.h>
- #include <cstdlib>
- #include <fstream>
- #include <cctype>
- #include <cassert>
- using namespace std;
- bool DEBUG = !true;
- struct Thrall
- {
- public:
- string surname;
- string name;
- string patronymic;
- int yaer;
- int subject_1, subject_2, subject_3, subject_4, subject_5;
- void print()
- {
- cout << surname << " " << name << " " << patronymic << ", " << yaer << " : ";
- printf("%i %i %i %i %i", subject_1, subject_2, subject_3, subject_4, subject_5);
- }
- };
- Thrall* init(ifstream &in, int &n)
- {
- in >> n;
- Thrall* res = new Thrall[n];
- string ts;
- int ti;
- for (int i = 0; i < n; i++)
- {
- in >> res[i].surname >> res[i].name >> res[i].patronymic >> res[i].yaer;
- in >> res[i].subject_1 >> res[i].subject_2 >> res[i].subject_3 >> res[i].subject_4 >> res[i].subject_5;
- }
- return res;
- }
- bool Thrall_cmp(Thrall a, Thrall b, bool (*dcmp) (string, string))
- {
- if (dcmp(a.surname, b.surname)) return true;
- if (dcmp(a.name, b.name)) return true;
- return dcmp(a.patronymic, b.patronymic);
- }
- bool scmp(string a, string b)
- {
- return a < b;
- }
- void pus_sort(Thrall* a, int n, bool (tcmp)(Thrall, Thrall, bool(*dcmp) (string, string)), bool(*dcmp) (string, string))
- {
- for (int i = 0; i < n - 1; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- if (tcmp(a[i], a[j], dcmp))
- {
- /*cout << "DBG: " << i << " <-> " << j << "\n";
- a[i].print();
- cout << "\n";
- a[j].print();
- cout << "\n";
- cout << "---\n";*/
- swap(a[i], a[j]);
- }
- }
- }
- }
- void vst_sort(Thrall* a, int n, bool (tcmp)(Thrall, Thrall, bool(*dcmp) (string, string)), bool(*dcmp) (string, string))
- {
- for(int i = 1; i < n; i++)
- {
- for(int j = i; j > 0 && tcmp(a[j], a[j - 1], dcmp); j--)
- {
- swap(a[j], a[j - 1]);
- }
- }
- }
- void vib_sort(Thrall* a, int n, bool (tcmp)(Thrall, Thrall, bool(*dcmp) (string, string)), bool(*dcmp) (string, string))
- {
- //
- }
- int main()
- {
- ifstream in1("input.txt");
- //ofstream out("output.txt");
- int n = 0;
- Thrall* a = init(in1, n);
- cout << n << "\n";
- for (int i = 0; i < n; i++)
- {
- a[i].print();
- cout << "\n";
- }
- cout << "----------------\n";
- pus_sort(a, n, Thrall_cmp, scmp);
- for (int i = 0; i < n; i++)
- {
- a[i].print();
- cout << "\n";
- }
- cout << "----------------\n";
- delete[] a;
- in1.close();
- //------2
- ifstream in2("input.txt");
- a = init(in2, n);
- vst_sort(a, n, Thrall_cmp, scmp);
- for (int i = 0; i < n; i++)
- {
- a[i].print();
- cout << "\n";
- }
- cout << "----------------\n";
- delete[] a;
- in2.close();
- //------3
- ifstream in3("input.txt");
- a = init(in3, n);
- vib_sort(a, n, Thrall_cmp, scmp);
- for (int i = 0; i < n; i++)
- {
- a[i].print();
- cout << "\n";
- }
- cout << "----------------\n";
- delete[] a;
- in3.close();
- getc(stdin);
- return 0;
- }
- /*
- 5
- Andreeva Irina fivaifva 2000 1 2 3 4 5
- Anferova Anastasia fivafiva 2000 1 2 3 4 5
- Belozub Ana ikerkier 2000 1 2 3 4 5
- Belous Aleksey euiriker 2000 1 2 3 4 5
- Kolodin Denis oar?ri 2000 1 2 3 4 5
- Kuzmin Dmitriy avro?vr?o 2000 1 2 3 4 5
- Pavlova Aleksandra iapotvao?v 2000 1 2 3 4 5
- Petrov Aleksey uriapovepr 2000 1 2 3 4 5
- Rokah Gleb vopvrl? 2000 1 2 3 4 5
- Sunaeva Ulia iriaor 2000 1 2 3 4 5
- Hkodin Maksim ikoiko 2000 1 2 3 4 5
- Bednov Andrey kioianoavi 2000 1 2 3 4 5
- Istomin Nikolay ioikovl 2000 1 2 3 4 5
- Komkov Nikita vaairtto? 2000 1 2 3 4 5
- Kotuma Andrey dflvorai 2000 1 2 3 4 5
- Kulagin Andrey ?zfioplo 2000 1 2 3 4 5
- Lanin Ivan dflvarpi?f 2000 1 2 3 4 5
- Loktev Il?a fijlvpolim 2000 1 2 3 4 5
- Putatinskiy Dmitriy ifldvat 2000 1 2 3 4 5
- Salautin Dmitriy divopf 2000 1 2 3 4 5
- Semenov Egor fiddjaom 2000 1 2 3 4 5
- Hmigin Semen ejlaotivf 2000 1 2 3 4 5
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement