SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <algorithm> | |
| 2 | #include <iostream> | |
| 3 | #include <vector> | |
| 4 | #include <string> | |
| 5 | ||
| 6 | using namespace std; | |
| 7 | ||
| 8 | string ReadLine() {
| |
| 9 | string s; | |
| 10 | getline(cin, s); | |
| 11 | return s; | |
| 12 | } | |
| 13 | ||
| 14 | int ReadLineWithNumber() {
| |
| 15 | int result; | |
| 16 | cin >> result; | |
| 17 | ReadLine(); | |
| 18 | return result; | |
| 19 | } | |
| 20 | ||
| 21 | vector<string> SplitIntoWords(const string& text) {
| |
| 22 | vector<string> words; | |
| 23 | string word; | |
| 24 | for (const char c : text) {
| |
| 25 | if (c == ' ') {
| |
| 26 | if (!word.empty()) {
| |
| 27 | words.push_back(word); | |
| 28 | word.clear(); | |
| 29 | } | |
| 30 | } else {
| |
| 31 | word += c; | |
| 32 | } | |
| 33 | } | |
| 34 | if (!word.empty()) {
| |
| 35 | words.push_back(word); | |
| 36 | } | |
| 37 | ||
| 38 | return words; | |
| 39 | } | |
| 40 | ||
| 41 | int main() {
| |
| 42 | const int queryCount = ReadLineWithNumber(); | |
| 43 | ||
| 44 | vector<string> queries(queryCount); | |
| 45 | for (string& query : queries) {
| |
| 46 | query = ReadLine(); | |
| 47 | } | |
| 48 | const string buzzword = ReadLine(); | |
| 49 | ||
| 50 | cout << count_if(queries.begin(), queries.end(), [buzzword](const string& query) {
| |
| 51 | const vector<string> query_words = SplitIntoWords(query); | |
| 52 | return count(query_words.begin(), query_words.end(), buzzword) != 0; | |
| 53 | }); | |
| 54 | cout << endl; | |
| 55 | } |