Advertisement
Infiniti_Inter

extra problem(78, I, quickSort)

Apr 11th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <exception>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. #define Line cout << "--------------------------------------------------\n"
  10. #define forn(i, n) for(int i = 0; i < int(n);i++)
  11. const int INF = 1e9 + 13;
  12. const int N = 1e5 + 13;
  13. ifstream in("input.txt");
  14. struct student {
  15.     int group;
  16.     string first_name, second_name, third_name;
  17.     int birth_year;
  18.     int marks[5];
  19.     void print();
  20.  
  21. };
  22. void student::print() {
  23.     Line;
  24.     cout << "group: " << group << "\nFull name: " << first_name << ' ' << second_name << ' ' << third_name << "\nbirth year: " << birth_year <<
  25.         "\n" << "marks: " << marks[0] << ' ' << marks[1] << ' ' << marks[2] << ' ' << marks[3] << ' ' << marks[4] << endl;
  26. }
  27. bool check(student a, student b) {
  28.     if (a.first_name < b.first_name)
  29.         return true;
  30.     else
  31.         if (a.second_name < b.second_name && a.first_name == b.first_name)
  32.             return true;
  33.         else
  34.             if (a.third_name < b.third_name && a.second_name == b.second_name && a.first_name == b.first_name)
  35.                 return true;
  36.  
  37.     return false;
  38. }
  39. student a[N];
  40.  
  41. void mySort(student* a, int l, int r) {
  42.     int i = l, j = r;
  43.     student pivot = a[(l + r) / 2];
  44.     while (i <= j)
  45.     {
  46.         while (check(a[i], pivot)) {
  47.             i++;
  48.         }
  49.         while (check(pivot, a[j])) {
  50.             j--;
  51.         }
  52.         if (i <= j){
  53.             student tmp = a[i];
  54.             a[i] = a[j];
  55.             a[j] = tmp;
  56.             j--;
  57.             i++;
  58.         }
  59.         if (l < j)
  60.             mySort(a, l, j);
  61.         if (i < r)
  62.             mySort(a, i, r);
  63.     }
  64. }
  65. student get_student() {
  66.     student res;
  67.     in >> res.group;
  68.     in >> res.first_name >> res.second_name >> res.third_name;
  69.     in >> res.birth_year;
  70.     forn(i, 5)
  71.         in >> res.marks[i];
  72.     return res;
  73. }
  74.  
  75. int main() {
  76.  
  77.     int n = 0;
  78.  
  79.     while (in.peek() != EOF)
  80.     {
  81.         a[n] = get_student();
  82.         if (a[n].first_name == "")
  83.             n--;
  84.         n++;
  85.     }
  86.     cout << n;
  87.     mySort(a, 0, n - 1);
  88.     forn(i, n)
  89.         a[i].print();
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement