Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <set>
- using namespace std;
- int CalculateSimilarity(vector<string> first, vector<string> second) {
- vector<string>inter;
- sort(first.begin(), first.end());
- sort(second.begin(), second.end());
- set_intersection(first.begin(), first.end(), second.begin(), second.end(), back_inserter(inter));
- return inter.size();
- }
- // SplitIntoWords разбивает строку text на слова и возвращает их в виде вектора
- // Слово - последовательность непробельных символов,
- // разделённых одним или более пробелов.
- 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;
- }
- int main() {
- string query, description;
- getline(cin, query);
- getline(cin, description);
- std::cout << CalculateSimilarity(SplitIntoWords(query), SplitIntoWords(description)) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement