Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <string>
- using namespace std;
- struct Student
- {
- int group;
- string F, I, O;
- int year, marks[5];
- Student scanInfo(ifstream& in)
- {
- in >> group >> F >> I >> O >> year;
- for (int i = 0; i < 5; ++i) in >> marks[i];
- }
- void printInfo(ofstream& out)
- {
- out << group << " " << F << " " << I << " " << O << " ";
- for (int i = 0; i < 5; ++i)
- {
- out << marks[i] << " ";
- }
- }
- };
- // Пузырёк
- int main()
- {
- ifstream in("input.txt");
- ofstream out("output.txt");
- int index = 0;
- Student* base = new Student[100];
- while (in.peek() != EOF)
- {
- base[index].scanInfo(in);
- index++;
- }
- for (int i = 0; i < index - 1; i++)
- {
- for (int j = 0; j < index - i - 1; j++)
- {
- double cur_sum = (base[j].marks[0] + base[j].marks[1] + base[j].marks[2] + base[j].marks[3] + base[j].marks[4]) / 5;
- double next_sum = (base[j + 1].marks[0] + base[j + 1].marks[1] + base[j + 1].marks[2] + base[j + 1].marks[3] + base[j + 1].marks[4]) / 5;
- if (cur_sum < next_sum)
- {
- Student tmp = base[j];
- base[j] = base[j + 1];
- base[j+1] = tmp;
- }
- }
- }
- for (int i = 0; i < index; ++i)
- {
- double sum = (base[i].marks[0] + base[i].marks[1] + base[i].marks[2] + base[i].marks[3] + base[i].marks[4]) / 5;
- base[i].printInfo(out);
- out << sum << endl;
- }
- in.close();
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement