Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- СДАТЬ.Сортировки, первая задача.
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- struct Student
- {
- string fam;
- string name;
- string secondName;
- int mas[5];
- void ScanStud();
- void PrintStud();
- };
- void Student::ScanStud()
- {
- fin >> fam >> name >> secondName;
- for (int i = 0; i < 5; i++)
- fin >> mas[i];
- };
- void Student::PrintStud()
- {
- fout << fam << " " << name << " " << secondName << " ";
- for (int i = 0; i < 5; i++)
- fout << mas[i] << " ";
- fout << endl;
- };
- void sort(Student* a, int n)
- {
- for (int i = n - 1; i >= 0; i--)
- {
- for (int j = 0; j < i; j++)
- {
- if (a[j].fam > a[j + 1].fam)
- {
- swap(a[j], a[j + 1]);
- }
- else if (a[j].fam == a[j + 1].fam && a[j].name > a[j + 1].name)
- {
- swap(a[j], a[j + 1]);
- }
- else if (a[j].fam == a[j + 1].fam && a[j].name == a[j + 1].name && a[j].secondName > a[j + 1].secondName)
- {
- swap(a[j], a[j + 1]);
- }
- }
- }
- }
- int main()
- {
- int n = 0;
- Student stud[10];
- while (fin.peek() != EOF)
- {
- stud[n].ScanStud();
- n++;
- }
- sort(stud, n);
- for (int i = 1; i < n; i++)
- {
- stud[i].PrintStud();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement