Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. struct student
  9. {
  10. string surname;
  11. char p;
  12. };
  13.  
  14. void printms(string *lines, int count_word)
  15. {
  16. for (int i = 0; i < count_word; i++)
  17. cout << lines[i] << "\n";
  18. cout << endl;
  19. }
  20.  
  21. string GetStrFromMyStr(string s, int N)
  22. {
  23. int i = 0;
  24. string buf;
  25. const char *temp = (s.c_str());
  26. while (i != N)
  27. {
  28. while (*temp != '\n')
  29. {
  30. if (i == N - 1) buf = buf + *temp;
  31. *temp++;
  32. }
  33. *temp++;
  34. i++;
  35. }
  36. return buf;
  37. }
  38.  
  39. void GetAllStrToStr(string *lines, string text, int count_word)
  40. {
  41. for (int i = 0; i < count_word; i++)
  42. lines[i] = GetStrFromMyStr(text, i + 1);
  43. }
  44.  
  45. void sortonalpha(string *S, int n)
  46. {
  47. for (int i = 0; i < n - 1; i++)
  48. for (int j = i + 1; j < n; j++)
  49. if (strcmp(S[i].c_str(), S[j].c_str())>0) swap(S[i], S[j]);
  50. }
  51.  
  52. void main()
  53. {
  54. setlocale(LC_ALL, "rus");
  55. ifstream f;
  56. stringstream ss;
  57. int N = 0, i = 0;
  58. string line, text, textwithgirls;
  59. int kol_bab = 0;
  60. f.open("input.txt", ios::in);
  61. while (!f.eof())
  62. {
  63. getline(f, line);
  64. text = text + line + '\n';
  65. N++;
  66. }
  67. student *students = new student[N];
  68. f.clear();
  69. f.seekg(0, ios_base::beg);
  70. while (!f.eof())
  71. {
  72. getline(f, line);
  73. ss.clear();
  74. ss.str(line);
  75. while (!ss.eof())
  76. {
  77. ss >> students[i].surname;
  78. ss >> students[i].p;
  79. }
  80. if (students[i].p == 'ж')
  81. {
  82. kol_bab++;
  83. textwithgirls = textwithgirls + line + '\n';
  84. }
  85. i++;
  86. }
  87. string *lines = new string[N];
  88. string *lineswg = new string[kol_bab];
  89. GetAllStrToStr(lines, text, N);
  90. GetAllStrToStr(lineswg, textwithgirls, kol_bab);
  91. sortonalpha(lineswg, kol_bab);
  92. int k = 0;
  93. for (i = 0; i < N; i++)
  94. {
  95. if (students[i].p == 'ж')
  96. {
  97. lines[i] = lineswg[k];
  98. k++;
  99. }
  100. }
  101. printms(lines, N);
  102. system("pause");
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement