Advertisement
12311k

Untitled

Apr 7th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. // final055.cpp без const-переменных, но с const-ссылками
  2.  
  3. #include <iostream>
  4. #include <set>
  5. #include <string>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. vector<string> SplitIntoWords(const string& text) {
  11. vector<string> words;
  12. string word;
  13. for (char c : text) {
  14. if (c == ' ') {
  15. words.push_back(word);
  16. word = "";
  17. } else {
  18. word += c;
  19. }
  20. }
  21. words.push_back(word);
  22.  
  23. return words;
  24. }
  25.  
  26. set<string> ParseStopWords(const string& text) {
  27. set<string> stop_words;
  28. for (const string& word : SplitIntoWords(text)) {
  29. stop_words.insert(word);
  30. }
  31. return stop_words;
  32. }
  33.  
  34. vector<string> ParseQuery(const string& text, const set<string>& stop_words) {
  35. vector<string> words;
  36. for (const string& word : SplitIntoWords(text)) {
  37. if (stop_words.count(word) == 0) {
  38. words.push_back(word);
  39. }
  40. }
  41. return words;
  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