Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #include <iostream>
 - #include <string>
 - #include <fstream>
 - #include <vector>
 - #include <algorithm>
 - #include <iomanip>
 - //Сначала по фамилии, потом по году рождения с помощью сортировки вставками
 - using namespace std;
 - //В файле содержатся данные о сотрудниках предприятия: ФИО, должность,
 - //дата рождения, стаж работы, зарплата (не менее 20 человек). В новый файл вывести
 - //данные, отсортированные по какому-либо ключу
 - struct worker
 - {
 - string surname;
 - string name;
 - string patronymic;
 - string position;
 - string birth_date;
 - string exp;
 - string salary;
 - };
 - string birthYear(string s)
 - {
 - return s.substr(s.length() - 4, 4);
 - }
 - void insertionSort(vector<worker> &vec, int n)
 - {
 - for(int i = 1; i < n; i++)
 - for(int j = i; j > 0 && (vec[j - 1].surname > vec[j].surname || vec[j - 1].surname == vec[j].surname && birthYear(vec[j - 1].birth_date) > birthYear(vec[j].birth_date)); j--)
 - swap(vec[j - 1], vec[j]);
 - }
 - int main()
 - {
 - ifstream in("in.txt");
 - ofstream out("out.txt");
 - vector<worker> vec;
 - while(in.peek() != EOF)
 - {
 - worker result;
 - in >> result.surname >> result.name >> result.patronymic >> result.position >> result.birth_date >> result.exp >> result.salary;
 - vec.push_back(result);
 - }
 - insertionSort(vec, vec.size());
 - for(int i = 0; i < vec.size(); i++)
 - {
 - out << left << setw(20) << vec[i].surname << setw(20) << vec[i].name << setw(20) << vec[i].patronymic << setw(20) << vec[i].position << setw(20) << vec[i].birth_date << setw(20) << vec[i].exp << setw(20) << vec[i].salary << endl;
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment