Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- struct student
- {
- string lastname;
- string firstname;
- string middlename;
- int year;
- int marks[5];
- };
- void print(vector<student>& group, ofstream& out)
- {
- for (int i = 0; i < group.size(); i++)
- {
- out << " " << left << group[i].lastname.c_str() << " " << group[i].firstname.c_str() << " " << group[i].middlename.c_str() << " " << group[i].year << " ";
- for (int j = 0; j < 5; j++)
- out << group[i].marks[j] << " ";
- out << endl;
- }
- }
- bool cmp(student& a, student& b) {
- if (a.lastname.compare(b.lastname) > 0 ) return false;
- else if (a.lastname.compare(b.lastname) < 0) return true;
- else {
- if (a.firstname.compare(b.firstname) > 0) return false;
- else if (a.firstname.compare(b.firstname) < 0) return true;
- else {
- if (a.middlename.compare(b.middlename) > 0) return false;
- else if (a.middlename.compare(b.middlename) <= 0) return true;
- }
- }
- return false;
- }
- int main(void)
- {
- ifstream in("input.txt");
- ofstream out("output.txt");
- vector<student> group;
- int n;
- in >> n;
- student t;
- string s;
- getline(in, s);
- while(in >> t.lastname >> t.firstname >> t.middlename >> t.year >> t.marks[0] >> t.marks[1] >> t.marks[2] >> t.marks[3] >> t.marks[4])
- group.push_back(t);
- sort(group.begin(), group.end(), cmp);
- print(group, out);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment