Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <set>
- #include <string>
- #include <utility>
- #include <vector>
- using namespace std;
- const int MAX_RESULT_DOCUMENT_COUNT = 5;
- string ReadLine() {
- string s;
- getline(cin, s);
- return s;
- }
- int ReadLineWithNumber() {
- int result = 0;
- cin >> result;
- ReadLine();
- return result;
- }
- vector<string> SplitIntoWords(const 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;
- }
- class SearchServer {
- public:
- void AddDocument(int document_id, const string& document) {
- const vector<string> words = SplitIntoWordsNoStop(document, stop_words_);
- documents_.push_back({ document_id, words });
- }
- set<string> SetStopWords(const string& text) {
- set<string> stop_words;
- for (const string& word : SplitIntoWords(text)) {
- stop_words_.insert(word);
- }
- return stop_words_;
- }
- private:
- struct DocumentContent {
- int id = 0;
- vector<string> words;
- };
- vector<string> SplitIntoWordsNoStop(const string& text, const set<string>& stop_words) {
- vector<string> words;
- for (const string& word : SplitIntoWords(text)) {
- if (stop_words.count(word) == 0) {
- words.push_back(word);
- }
- }
- return words;
- }
- vector<DocumentContent> documents_;
- set<string> stop_words_;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement