Advertisement
myloyo

вроде нестейбл

May 18th, 2023 (edited)
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8. ifstream in("input.txt");
  9. ofstream out("output.txt");
  10.  
  11. struct student {
  12.     string fam, imya, otch;
  13.     int chisl, mec, year;
  14.     int oc[5];
  15.     int summa();
  16.     void vvod() {
  17.         in >> fam >> imya >> otch >> chisl >> mec >> year;
  18.         for (int j = 0; j < 5; j++) {
  19.             in >> oc[j];
  20.         }
  21.     }
  22.  
  23.     void vivod() {
  24.         out << fam << " " << imya << " " << otch << " " << chisl << " " << mec << " " << year << " ";
  25.         for (int j = 0; j < 5; j++) {
  26.             out << oc[j] << " ";
  27.         }
  28.         out << endl;
  29.     }
  30. };
  31. int student::summa() {
  32.     return oc[0] + oc[1] + oc[2] + oc[3] + oc[4];
  33. }
  34.  
  35. bool comparator(student left, student right) {
  36.     return(left.summa() < right.summa()); //&& left.fam < right.fam);
  37. }
  38.  
  39. int main() {
  40.     int n;
  41.     in >> n;
  42.     vector <student> a;
  43.     student t;
  44.     for (int i = 0; i < n; i++) {
  45.         t.vvod();
  46.         a.push_back(t);
  47.     }
  48.  
  49.     sort(a.begin(), a.end(), comparator);
  50.  
  51.     for (int i = 0; i < n; i++) {
  52.         a[i].vivod();
  53.     }
  54.  
  55.     int j;
  56.     in >> j;
  57.     vector <student> b;
  58.     student y;
  59.     for (int i = 0; i < j; i++) {
  60.         y.vvod();
  61.         b.push_back(y);
  62.     }
  63.  
  64.     stable_sort(b.begin(), b.end(), comparator);
  65.  
  66.     for (int i = 0; i < j; i++) {
  67.         b[i].vivod();
  68.     }
  69.  
  70.     return 0;
  71. }
  72. /*
  73. 3
  74. MYLNIKOVA N S 24 7 2004 5 5 5 5 5
  75. mylnikova n s 24 7 2004 5 5 5 5 5
  76. a a a 10 2 2007 2 2 2 2 2
  77. 3
  78. MYLNIKOVA N S 24 7 2004 5 5 5 5 5
  79. mylnikova n s 24 7 2004 5 5 5 5 5
  80. a a a 10 2 2007 2 2 2 2 2
  81. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement