Advertisement
al3taibi

Untitled

May 30th, 2022
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void process(string line, string word) {
  6.     string temp;
  7.     char tmp, tmp2;
  8.     int i, k;
  9.     bool has = false;
  10.  
  11.     for (i = 0; i < line.length(); i++) {
  12.         tmp = line[i];
  13.  
  14.         temp += tmp;
  15.  
  16.         if(tolower(tmp) == tolower(word[0]))
  17.         {
  18.             for(k = i; k < i + word.size(); k++)
  19.             {
  20.                 tmp2 = tolower(line[k]);
  21.  
  22.                 if(tmp2 == tolower(word[k - i]))
  23.                 {
  24.                     has = true;
  25.                 }
  26.                 else
  27.                 {
  28.                     has = false;
  29.                     break;
  30.                 }
  31.             }
  32.         }
  33.  
  34.         if(tmp == '.' || tmp == '!' || tmp == '?')
  35.         {
  36.             if(has)
  37.             {
  38.                 cout << temp << endl;
  39.                 has = false;
  40.             }
  41.             temp = "";
  42.         }
  43.     }
  44.     cout << endl;
  45. }
  46.  
  47. int main() {
  48.     string line = "The sea was really rough and the waves were huge. -It was so exciting! -Canoe was full of water but we weren't scary.", word;
  49.  
  50.     getline(cin, line);
  51.     cin >> word;
  52.  
  53.     process(line, word);
  54.  
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement