Advertisement
xxeell

Untitled

Apr 16th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdio.h>
  4. #include <cstdlib>
  5. #include <fstream>
  6. #include <cctype>
  7. #include <cassert>
  8. using namespace std;
  9.  
  10. bool DEBUG = !true;
  11.  
  12. struct Thrall
  13. {
  14. public:
  15.     string surname;
  16.     string name;
  17.     string patronymic;
  18.     int yaer;
  19.     int subject_1, subject_2, subject_3, subject_4, subject_5;
  20.  
  21.     void print()
  22.     {
  23.         cout << surname << " " << name << " " << patronymic << ", " << yaer << " : ";
  24.         printf("%i %i %i %i %i", subject_1, subject_2, subject_3, subject_4, subject_5);
  25.     }
  26. };
  27.  
  28. Thrall* init(ifstream &in, int &n)
  29. {
  30.     in >> n;
  31.     Thrall* res = new Thrall[n];
  32.     string ts;
  33.     int ti;
  34.  
  35.     for (int i = 0; i < n; i++)
  36.     {
  37.         in >> res[i].surname >> res[i].name >> res[i].patronymic >> res[i].yaer;
  38.         in >> res[i].subject_1 >> res[i].subject_2 >> res[i].subject_3 >> res[i].subject_4 >> res[i].subject_5;
  39.     }
  40.     return res;
  41. }
  42.  
  43. bool Thrall_cmp(Thrall a, Thrall b, bool (*dcmp) (string, string))
  44. {
  45.     if (dcmp(a.surname, b.surname)) return true;
  46.     if (dcmp(a.name, b.name)) return true;
  47.     return dcmp(a.patronymic, b.patronymic);
  48. }
  49.  
  50. bool scmp(string a, string b)
  51. {
  52.     return a < b;
  53. }
  54.  
  55. void pus_sort(Thrall* a, int n, bool (tcmp)(Thrall, Thrall, bool(*dcmp) (string, string)), bool(*dcmp) (string, string))
  56. {
  57.     for (int i = 0; i < n - 1; i++)
  58.     {
  59.         for (int j = i + 1; j < n; j++)
  60.         {
  61.             if (tcmp(a[i], a[j], dcmp))
  62.             {
  63.                 /*cout << "DBG: " << i << " <-> " << j << "\n";
  64.                 a[i].print();
  65.                 cout << "\n";
  66.                 a[j].print();
  67.                 cout << "\n";
  68.                 cout << "---\n";*/
  69.  
  70.                 swap(a[i], a[j]);
  71.             }
  72.         }
  73.     }
  74. }
  75.  
  76. void vst_sort(Thrall* a, int n, bool (tcmp)(Thrall, Thrall, bool(*dcmp) (string, string)), bool(*dcmp) (string, string))
  77. {
  78.     for(int i = 1; i < n; i++)
  79.     {
  80.         for(int j = i; j > 0 && tcmp(a[j], a[j - 1], dcmp); j--)
  81.         {
  82.             swap(a[j], a[j - 1]);
  83.         }
  84.     }
  85. }
  86.  
  87. void vib_sort(Thrall* a, int n, bool (tcmp)(Thrall, Thrall, bool(*dcmp) (string, string)), bool(*dcmp) (string, string))
  88. {
  89.     //
  90. }
  91.  
  92. int main()
  93. {
  94.     ifstream in1("input.txt");
  95.     //ofstream out("output.txt");
  96.  
  97.     int n = 0;
  98.  
  99.     Thrall* a = init(in1, n);
  100.  
  101.     cout << n << "\n";
  102.  
  103.     for (int i = 0; i < n; i++)
  104.     {
  105.         a[i].print();
  106.         cout << "\n";
  107.     }
  108.     cout << "----------------\n";
  109.  
  110.     pus_sort(a, n, Thrall_cmp, scmp);
  111.  
  112.     for (int i = 0; i < n; i++)
  113.     {
  114.         a[i].print();
  115.         cout << "\n";
  116.     }
  117.  
  118.     cout << "----------------\n";
  119.     delete[] a;
  120.     in1.close();
  121.     //------2
  122.     ifstream in2("input.txt");
  123.     a = init(in2, n);
  124.  
  125.     vst_sort(a, n, Thrall_cmp, scmp);
  126.  
  127.     for (int i = 0; i < n; i++)
  128.     {
  129.         a[i].print();
  130.         cout << "\n";
  131.     }
  132.  
  133.     cout << "----------------\n";
  134.     delete[] a;
  135.     in2.close();
  136.     //------3
  137.     ifstream in3("input.txt");
  138.     a = init(in3, n);
  139.  
  140.     vib_sort(a, n, Thrall_cmp, scmp);
  141.  
  142.     for (int i = 0; i < n; i++)
  143.     {
  144.         a[i].print();
  145.         cout << "\n";
  146.     }
  147.  
  148.     cout << "----------------\n";
  149.     delete[] a;
  150.     in3.close();
  151.  
  152.     getc(stdin);
  153.     return 0;
  154. }
  155.  
  156. /*
  157. 5
  158. Andreeva Irina fivaifva 2000 1 2 3 4 5
  159. Anferova Anastasia fivafiva 2000 1 2 3 4 5
  160. Belozub Ana ikerkier 2000 1 2 3 4 5
  161. Belous Aleksey euiriker 2000 1 2 3 4 5
  162. Kolodin Denis oar?ri 2000 1 2 3 4 5
  163. Kuzmin Dmitriy avro?vr?o 2000 1 2 3 4 5
  164. Pavlova Aleksandra iapotvao?v 2000 1 2 3 4 5
  165. Petrov Aleksey uriapovepr 2000 1 2 3 4 5
  166. Rokah Gleb vopvrl? 2000 1 2 3 4 5
  167. Sunaeva Ulia iriaor 2000 1 2 3 4 5
  168. Hkodin Maksim ikoiko 2000 1 2 3 4 5
  169. Bednov Andrey kioianoavi 2000 1 2 3 4 5
  170. Istomin Nikolay ioikovl 2000 1 2 3 4 5
  171. Komkov Nikita vaairtto? 2000 1 2 3 4 5
  172. Kotuma Andrey dflvorai 2000 1 2 3 4 5
  173. Kulagin Andrey ?zfioplo 2000 1 2 3 4 5
  174. Lanin Ivan dflvarpi?f 2000 1 2 3 4 5
  175. Loktev Il?a fijlvpolim 2000 1 2 3 4 5
  176. Putatinskiy Dmitriy ifldvat 2000 1 2 3 4 5
  177. Salautin Dmitriy divopf 2000 1 2 3 4 5
  178. Semenov Egor fiddjaom  2000 1 2 3 4 5
  179. Hmigin Semen ejlaotivf 2000 1 2 3 4 5
  180. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement