Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- struct Student {
- string Imya, Familiya, Otchestvo;
- int Kurs, Gruppa;
- double Time;
- string _fioSort = "";
- string fioSort();
- void initialize(ifstream &in);
- string toString();
- };
- void Student::initialize(ifstream &in){
- string temp;
- in >> this->Familiya >> this->Imya >> this->Otchestvo >> temp;
- this->Kurs = stoi(temp);
- in >> temp;
- this->Gruppa = stoi(temp);
- in >> temp;
- this->Time = stod(temp);
- }
- string Student::toString() {
- string res = this->Familiya + " "
- + this->Imya + " "
- + this->Otchestvo + " "
- + to_string(this->Kurs) + " "
- + to_string(this->Gruppa) + " "
- + to_string(this->Time);
- return res;
- }
- string Student::fioSort (){
- if (!this->_fioSort.length){
- this->_fioSort = Familiya + Imya + Otchestvo;
- }
- return this->_fioSort;
- }
- void shellSort(Student *arr, int length){
- Student temp;
- int i, j, incr = length / 2;
- while (incr > 0){
- for(i = incr; i < length; i++){
- j = i - incr;
- while(j >= 0)
- if (arr[j + incr].fioSort().compare(arr[j].fioSort())){
- temp = arr[j];
- arr[j] = arr[j + incr];
- arr[j + incr] = temp;
- j = j - incr;
- }
- else{
- j = -1;
- }
- incr = incr / 2;
- }
- }
- }
- int main() {
- setlocale(LC_ALL, "Russian");
- long studCount; string temp; int gruppa;
- ifstream in("input.txt");
- ofstream out("output.txt");
- if (!in) return 0; // Файл пуст
- in >> temp;
- studCount = stol(temp);
- auto students = new Student[studCount];
- cout << "Не отсортированные:";
- for (auto s = students; s < students + studCount; s++) {
- s->initialize(in);
- cout << " " << s->toString();
- }
- in.close();
- shellSort(students, studCount);
- cout << "Отсортированные:";
- for (auto s = students; s < students + studCount; s++) {
- temp = s->toString();
- cout << " " + temp;
- out << temp;
- }
- out.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment