Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <fstream>
- using namespace std;
- struct student
- {
- string surname;
- char p;
- };
- void printms(string *lines, int count_word)
- {
- for (int i = 0; i < count_word; i++)
- cout << lines[i] << "\n";
- cout << endl;
- }
- string GetStrFromMyStr(string s, int N)
- {
- int i = 0;
- string buf;
- const char *temp = (s.c_str());
- while (i != N)
- {
- while (*temp != '\n')
- {
- if (i == N - 1) buf = buf + *temp;
- *temp++;
- }
- *temp++;
- i++;
- }
- return buf;
- }
- void GetAllStrToStr(string *lines, string text, int count_word)
- {
- for (int i = 0; i < count_word; i++)
- lines[i] = GetStrFromMyStr(text, i + 1);
- }
- void sortonalpha(string *S, int n)
- {
- for (int i = 0; i < n - 1; i++)
- for (int j = i + 1; j < n; j++)
- if (strcmp(S[i].c_str(), S[j].c_str())>0) swap(S[i], S[j]);
- }
- void main()
- {
- setlocale(LC_ALL, "rus");
- ifstream f;
- stringstream ss;
- int N = 0, i = 0;
- string line, text, textwithgirls;
- int kol_bab = 0;
- f.open("input.txt", ios::in);
- while (!f.eof())
- {
- getline(f, line);
- text = text + line + '\n';
- N++;
- }
- student *students = new student[N];
- f.clear();
- f.seekg(0, ios_base::beg);
- while (!f.eof())
- {
- getline(f, line);
- ss.clear();
- ss.str(line);
- while (!ss.eof())
- {
- ss >> students[i].surname;
- ss >> students[i].p;
- }
- if (students[i].p == 'ж')
- {
- kol_bab++;
- textwithgirls = textwithgirls + line + '\n';
- }
- i++;
- }
- string *lines = new string[N];
- string *lineswg = new string[kol_bab];
- GetAllStrToStr(lines, text, N);
- GetAllStrToStr(lineswg, textwithgirls, kol_bab);
- sortonalpha(lineswg, kol_bab);
- int k = 0;
- for (i = 0; i < N; i++)
- {
- if (students[i].p == 'ж')
- {
- lines[i] = lineswg[k];
- k++;
- }
- }
- printms(lines, N);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement