Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<algorithm>
- #include<set>
- #include<map>
- #include<vector>
- #include<stdlib.h>
- #include<iterator>
- #include<string>
- using namespace std;
- multiset<string> s1; // множество слов
- set<string>st; // множество слов без повторений
- multiset<string>s2; // множество слов2
- int main()
- {
- setlocale(LC_ALL, "RUS");
- int n;
- string s;
- getline(cin, s); // считываем текст
- string cnt = ""; // строка для первого слова
- int pos1 = -1;
- int j = 0;
- for (int i = 0; i < s.size(); i = j) {
- if (isalpha(s[i]) && pos1 == -1) { // если буква и ещё не начало слова
- pos1 = i; // первая позиция слова
- j = i; // конец слова
- while (isalpha(s[j]) && j < s.size()) {
- j++;
- }
- s1.insert(s.substr(pos1, j - pos1)); // добавляем слово в соответствующее множество
- st.insert(s.substr(pos1, j - pos1)); // добавляем слово
- pos1 = -1;
- }
- else if (isalpha(s[i]) && pos1 == -1) { // если слово и ещё не началось слово
- pos1 = i; // первая позиция слова
- j = i; // конец слова
- while (isalpha(s[j]) && j < s.size()) {
- j++;
- }
- if (cnt == "") { // если первое слова ещё не было найдено
- cnt = s.substr(pos1, j - pos1); // первое слово
- }
- s2.insert(s.substr(pos1, j - pos1)); // добавляем слово в множество
- pos1 = -1;
- }
- else {
- j++;
- }
- }
- for (auto it = st.begin(); it != st.end(); it++) {
- if (s1.count(*it) == s2.count(cnt)) cout << *it << endl; // если слово вхождений текущего слова равно числу вхождений первого слово, то выводим слово
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement