Advertisement
Infiniti_Inter

78 1 (7)

May 14th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. ifstream in("input.txt");
  8. ofstream out("output.txt");
  9. struct Student
  10. {
  11.     string firstName, surname, lastName;
  12.     int yearOfBirdth;
  13.     int mark[5];
  14.     int sum = 0;
  15.  
  16.     void get()
  17.     {
  18.         in >> firstName >> surname >> lastName >> yearOfBirdth;
  19.         for (int i = 0; i < 5; ++i)
  20.         {
  21.             in >> mark[i];
  22.             sum += mark[i];
  23.         }
  24.     }
  25.     void print()
  26.     {
  27.         out << firstName << ' ' << surname << ' '<< lastName << '\n' <<  yearOfBirdth << '\n';
  28.         for (int i = 0; i < 5; ++i)
  29.             out << mark[i] << ' ';
  30.         out << '\n' << "sum :" << sum << "\n\n";
  31.     }
  32. };
  33.  
  34.  
  35.  
  36.  
  37. const int MAXSIZE = 100;
  38. int main()
  39. {
  40.     Student a[MAXSIZE];
  41.     int n = 0;
  42.     int group;
  43.     in >> group;
  44.     while (in.peek() != EOF)
  45.     {
  46.         a[n].get();
  47.         n++;
  48.     }
  49.     for (int i = 0; i < n; ++i)
  50.     {
  51.         int idx = i;
  52.         for (int j = i; j < n; ++j)
  53.             if (a[j].sum < a[idx].sum)
  54.                 idx = j;
  55.         Student cur = a[idx];
  56.         a[idx] = a[i];
  57.         a[i] = cur;
  58.     }
  59.  
  60.     out << group << "\n\n";
  61.     for (int i = 0; i < n; ++i)
  62.         a[i].print();
  63.  
  64.  
  65.     /*
  66.     пример входного файла:
  67.     181
  68.     krisa V S
  69.     2001
  70.     2 2 2 2 2
  71.     Ololosha D V
  72.     2000
  73.     5 5 5 5 5
  74.     Akakij K A
  75.     2002
  76.     1 2 3 4 5
  77.     */
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement