Advertisement
Infiniti_Inter

page 78 num 20

Mar 14th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 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.             else
  34.                 if (a.birth_year > b.birth_year && a.third_name == b.third_name)
  35.                     return true;
  36.     return false;
  37. }
  38. void MySort(student* a, int n){
  39.     forn(i, n)
  40.         for (int j = i + 1; j < n; ++j)
  41.             if (check(a[j], a[i]))
  42.                 swap(a[i], a[j]);
  43. }
  44. student get_student(){
  45.     student res;
  46.     in >> res.group;
  47.     in >> res.first_name >> res.second_name >> res.third_name;
  48.     in >> res.birth_year;
  49.     forn(i, 5)
  50.         in >> res.marks[i];
  51.     return res;
  52. }
  53.   student a[N];
  54. int main(){
  55.  
  56.     int n = 0;
  57.  
  58.     while (in.peek() != EOF)
  59.     {
  60.         a[n] = get_student();
  61.         if (a[n].first_name == "")
  62.             n--;
  63.         n++;
  64.     }
  65.     MySort(a, n);
  66.     forn(i, n)
  67.         a[i].print();
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement