Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <iomanip>
- using namespace std;
- struct Student
- {
- string surname;
- string name;
- string patronymic;
- int year;
- int marks [5];
- };
- void qsort(Student *a, int l, int r)
- {
- int i = l, j = r;
- string p = a[(i + j) / 2].surname;
- while ( i <= j )
- {
- while ( a[i].surname < p ) i++;
- while ( p < a[j].surname ) j--;
- if (i <= j)
- {
- swap (a[i], a[j]);
- i++; j--;
- }
- }
- if ( l < j ) qsort(a, l, j);
- if ( i < r ) qsort(a, i, r);
- }
- int main()
- {
- int n=0;
- Student list [100];
- ifstream inp ("list.txt");
- setlocale(LC_ALL,"Russian");
- while (inp.peek()!=EOF)
- {
- inp >> list[n].surname;
- inp >> list[n].name;
- inp >> list[n].patronymic;
- inp >> list[n].year;
- for(int i=0; i < 5; i++)
- inp >> list[n].marks[i];
- n++;
- }
- qsort(list, 0, n-1);
- ofstream out ("list2.txt");
- for( int i = 0; i < n; i++)
- {
- out << list[i].surname << " " << list[i].name << " " << list[i].patronymic << " " << list[i].year << " ";
- for(int j = 0; j < 5; j++)
- out << list[i].marks[j] << " ";
- out << endl;
- }
- inp.close();
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment