Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <iomanip>
- using namespace std;
- struct student
- {
- int grp;
- string lastname;
- string firstname;
- string middlename;
- int year;
- int marks[5];
- int sum;
- };
- void sort(vector <student>& group)
- {
- int step = group.size() / 2;
- while (step > 0)
- {
- for (int i = 0; i < (group.size() - step); i++)
- {
- int j = i;
- while (j >= 0 && group[j].lastname.compare(group[j + step].lastname) > 0)
- {
- //меняем их местами
- student temp = group[j];
- group[j] = group[j + step];
- group[j + step] = temp;
- j--;
- }
- }
- step = step / 2;//уменьшаем шаг
- }
- }
- void print(vector<student>& group)
- {
- for (int i = 0; i < group.size(); i++)
- {
- cout << setw(4) << left << group[i].grp << setw(12) << group[i].lastname.c_str() << setw(10) << group[i].firstname.c_str() << setw(15) << group[i].middlename.c_str() << setw(5) << group[i].year;
- for (int j = 0; j < 5; j++)
- cout << group[i].marks[j] << " ";
- cout << setw(4) << group[i].sum;
- cout << endl;
- }
- }
- int main(void)
- {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- vector<student> group;
- student t;
- string s;
- getline(cin, s);
- while(cin >> t.grp >> t.lastname >> t.firstname >> t.middlename >> t.year >> t.marks[0] >> t.marks[1] >> t.marks[2] >> t.marks[3] >> t.marks[4])
- {
- t.sum = 0;
- for (int i = 0; i < 5; i++)
- t.sum += t.marks[i];
- group.push_back(t);
- }
- print(group);
- sort(group);
- cout<<"\n-----\n";
- print(group);
- }
Advertisement
Add Comment
Please, Sign In to add comment