Advertisement
mr1302

SIAOD3.1

Oct 12th, 2021
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<string> check_substr(vector<string>& words, string substr){
  6.     vector<string> matched;
  7.     for(string & word : words){
  8.         if(word.size() >= substr.size()) {
  9.             bool unmatched = false;
  10.             for (int j = 0; j < substr.size(); ++j) {
  11.                 if(substr[j] != word[j]) {
  12.                     unmatched = true;
  13.                     break;
  14.                 }
  15.             }
  16.             if(!unmatched)
  17.                 matched.push_back(word);
  18.         }
  19.     }
  20.     return matched;
  21. }
  22.  
  23. vector<string> separate_words(const string & text, const string & delimeters){
  24.     vector<string> words;
  25.     string temp_s = "";
  26.     for(char i : text){
  27.         if(find(delimeters.begin(), delimeters.end(), i) == delimeters.end()){
  28.             temp_s += i;
  29.         }
  30.         else{
  31.             words.push_back(temp_s);
  32.             temp_s = "";
  33.         }
  34.     }
  35.     words.push_back(temp_s);
  36.     return words;
  37. }
  38.  
  39. int main() {
  40.     string substr = "", s = "";
  41.     cin >> substr >> s;
  42.     vector<string> words = separate_words(s, " ,.;!?:/");
  43.     vector<string> matched = check_substr(words, substr);
  44.     for(string i : matched){
  45.         cout << i << '\n';
  46.     }
  47.     return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement