Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <exception>
- using namespace std;
- #define Line cout << "--------------------------------------------------\n"
- #define forn(i, n) for(int i = 0; i < int(n);i++)
- const int INF = 1e9 + 13;
- const int N = 1e5 + 13;
- ifstream in("input.txt");
- struct student {
- int group;
- string first_name, second_name, third_name;
- int birth_year;
- int marks[5];
- void print();
- };
- void student::print() {
- Line;
- cout << "group: " << group << "\nFull name: " << first_name << ' ' << second_name << ' ' << third_name << "\nbirth year: " << birth_year <<
- "\n" << "marks: " << marks[0] << ' ' << marks[1] << ' ' << marks[2] << ' ' << marks[3] << ' ' << marks[4] << endl;
- }
- bool check(student a, student b) {
- if (a.first_name < b.first_name)
- return true;
- else
- if (a.second_name < b.second_name && a.first_name == b.first_name)
- return true;
- else
- if (a.third_name < b.third_name && a.second_name == b.second_name && a.first_name == b.first_name)
- return true;
- return false;
- }
- student a[N];
- void mySort(student* a, int l, int r) {
- int i = l, j = r;
- student pivot = a[(l + r) / 2];
- while (i <= j)
- {
- while (check(a[i], pivot)) {
- i++;
- }
- while (check(pivot, a[j])) {
- j--;
- }
- if (i <= j){
- student tmp = a[i];
- a[i] = a[j];
- a[j] = tmp;
- j--;
- i++;
- }
- if (l < j)
- mySort(a, l, j);
- if (i < r)
- mySort(a, i, r);
- }
- }
- student get_student() {
- student res;
- in >> res.group;
- in >> res.first_name >> res.second_name >> res.third_name;
- in >> res.birth_year;
- forn(i, 5)
- in >> res.marks[i];
- return res;
- }
- int main() {
- int n = 0;
- while (in.peek() != EOF)
- {
- a[n] = get_student();
- if (a[n].first_name == "")
- n--;
- n++;
- }
- cout << n;
- mySort(a, 0, n - 1);
- forn(i, n)
- a[i].print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement