fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5.  
  6. bool isSubstr(const std::string & s, size_t start, const std::string & pattern)
  7. {
  8. for (auto i = 0; i < pattern.size(); i++)
  9. {
  10. if (s[start + i] != pattern[i])
  11. {
  12. return false;
  13. }
  14. }
  15. return true;
  16. }
  17.  
  18. bool isSubstr(const std::string & word, const std::string & pattern)
  19. {
  20. for (auto i = 0; i < word.size() - pattern.size() + 1; i++)
  21. {
  22. if (isSubstr(word, i, pattern))
  23. {
  24. return true;
  25. }
  26. }
  27. return false;
  28. }
  29.  
  30. int main() {
  31. string word="abc";
  32. vector<string> patterns {"a","abc","bc","d","ef"};
  33. for (auto &pattern : patterns)
  34. std::cout << pattern << " " << isSubstr(word, pattern) << "\n";
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5472KB
stdin
Standard input is empty
stdout
a 1
abc 1
bc 1
d 0
ef 0