Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<set>
  4. #include<map>
  5. #include<vector>
  6. #include<stdlib.h>
  7. #include<iterator>
  8. #include<string>
  9. using namespace std;
  10.  
  11. multiset<string> s1; // множество слов
  12. set<string>st; // множество слов без повторений
  13. multiset<string>s2; // множество слов2
  14. int main()
  15. {
  16. setlocale(LC_ALL, "RUS");
  17. int n;
  18. string s;
  19. getline(cin, s); // считываем текст
  20. string cnt = ""; // строка для первого слова
  21. int pos1 = -1;
  22. int j = 0;
  23. for (int i = 0; i < s.size(); i = j) {
  24. if (isalpha(s[i]) && pos1 == -1) { // если буква и ещё не начало слова
  25. pos1 = i; // первая позиция слова
  26. j = i; // конец слова
  27. while (isalpha(s[j]) && j < s.size()) {
  28. j++;
  29. }
  30. s1.insert(s.substr(pos1, j - pos1)); // добавляем слово в соответствующее множество
  31. st.insert(s.substr(pos1, j - pos1)); // добавляем слово
  32. pos1 = -1;
  33. }
  34. else if (isalpha(s[i]) && pos1 == -1) { // если слово и ещё не началось слово
  35. pos1 = i; // первая позиция слова
  36. j = i; // конец слова
  37. while (isalpha(s[j]) && j < s.size()) {
  38. j++;
  39. }
  40. if (cnt == "") { // если первое слова ещё не было найдено
  41. cnt = s.substr(pos1, j - pos1); // первое слово
  42. }
  43. s2.insert(s.substr(pos1, j - pos1)); // добавляем слово в множество
  44. pos1 = -1;
  45. }
  46. else {
  47. j++;
  48. }
  49. }
  50.  
  51. for (auto it = st.begin(); it != st.end(); it++) {
  52. if (s1.count(*it) == s2.count(cnt)) cout << *it << endl; // если слово вхождений текущего слова равно числу вхождений первого слово, то выводим слово
  53. }
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement