Advertisement
Ermolaxe

СДАТЬ.Сортировки, первая задача.

Apr 4th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. СДАТЬ.Сортировки, первая задача.
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. ifstream fin("input.txt");
  9. ofstream fout("output.txt");
  10.  
  11. struct Student
  12. {
  13.     string fam;
  14.     string name;
  15.     string secondName;
  16.     int mas[5];
  17.     void ScanStud();
  18.     void PrintStud();
  19. };
  20. void Student::ScanStud()
  21. {
  22.     fin >> fam >> name >> secondName;
  23.     for (int i = 0; i < 5; i++)
  24.         fin >> mas[i];
  25. };
  26. void Student::PrintStud()
  27. {
  28.     fout << fam << " " << name << " " << secondName << " ";
  29.     for (int i = 0; i < 5; i++)
  30.         fout << mas[i] << " ";
  31.     fout << endl;
  32. };
  33. void sort(Student* a, int n)
  34. {
  35.     for (int i = n - 1; i >= 0; i--)
  36.     {
  37.         for (int j = 0; j < i; j++)
  38.         {
  39.             if (a[j].fam > a[j + 1].fam)
  40.             {
  41.                 swap(a[j], a[j + 1]);
  42.             }
  43.             else if (a[j].fam == a[j + 1].fam && a[j].name > a[j + 1].name)
  44.             {
  45.                 swap(a[j], a[j + 1]);
  46.             }
  47.             else if (a[j].fam == a[j + 1].fam && a[j].name == a[j + 1].name && a[j].secondName > a[j + 1].secondName)
  48.             {
  49.                 swap(a[j], a[j + 1]);
  50.             }
  51.         }
  52.     }
  53. }
  54.  
  55. int main()
  56. {
  57.     int n = 0;
  58.     Student stud[10];
  59.     while (fin.peek() != EOF)
  60.     {
  61.         stud[n].ScanStud();
  62.         n++;
  63.     }
  64.     sort(stud, n);
  65.     for (int i = 1; i < n; i++)
  66.     {
  67.         stud[i].PrintStud();
  68.     }
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement