Advertisement
chevengur

Вводный курс: основы C++ | Урок 2: Глубокое копирование

Sep 1st, 2023
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. vector<string> SplitIntoWords(string& text) {
  10.     vector<string> words;
  11.     string word;
  12.     for (int i = 0; i < text.size(); ++i) {
  13.         if (text[i] == ' ') {
  14.             words.push_back(word);
  15.             word = ""s;
  16.         } else {
  17.             word += text[i];
  18.         }
  19.     }
  20.     words.push_back(word);
  21.    
  22.     return words;
  23. }
  24.  
  25. set<string> ParseStopWords(string& text) {
  26.     set<string> stop_words;
  27.     for (string word : SplitIntoWords(text)) {
  28.         stop_words.insert(word);
  29.     }
  30.     return stop_words;
  31. }
  32.  
  33. vector<string> ParseQuery(string& text, set<string>&stop_words) {
  34.     vector<string> words;
  35.     for (string word : SplitIntoWords(text)) {
  36.         if (stop_words.count(word) == 0) {
  37.             words.push_back(word);
  38.         }
  39.     }
  40.     return words;
  41. }
  42.  
  43.  
  44. int main() {
  45.     // Read stop words
  46.     string stop_words_joined;
  47.     getline(cin, stop_words_joined);
  48.     set<string> stop_words = ParseStopWords(stop_words_joined);
  49.    
  50.     // Read query
  51.     string query;
  52.     getline(cin, query);
  53.     vector<string> query_words = ParseQuery(query, stop_words);
  54.    
  55.     for (const string& word : query_words) {
  56.         cout << '[' << word << ']' << endl;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement