Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <set>
- #include <vector>
- using namespace std;
- vector<string> SplitIntoWords(string text) {
- vector<string> words;
- string word;
- for (const char c : text) {
- if (c == ' ') {
- if (!word.empty()) {
- words.push_back(word);
- word.clear();
- }
- }
- else {
- word += c;
- }
- }
- if (!word.empty()) {
- words.push_back(word);
- }
- return words;
- }
- set<string>ParseStopWords(string words) {
- set<string>stop_words;
- for (const auto& word : SplitIntoWords(words)) {
- stop_words.insert(word);
- }
- return stop_words;
- }
- vector<string>ParseQuery(string words, set<string>stop_words) {
- vector<string>query_words;
- for (const auto& word : SplitIntoWords(words)) {
- if (stop_words.count(word) == 0) {
- query_words.push_back(word);
- }
- }
- return query_words;
- }
- int main() {
- /* Считайте строку со стоп-словами */
- string stop_words;
- getline(cin, stop_words);
- auto get_stop_words = ParseStopWords(stop_words);
- // Считываем строку-запрос
- string query;
- getline(cin, query);
- auto get_query_words = ParseQuery(query, get_stop_words);
- // Выведите только те слова, которых нет среди стоп-слов
- for (string word : get_query_words) {
- cout << '[' << word << ']' << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement