Advertisement
Infiniti_Inter

Page 78 problem 18

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