#include <iostream>
#include <vector>
// Function to check if all words exist in string s
bool allWordsExist(const std::string &s, const std::vector<std::string> &words) {
for (const std::string &w : words) {
if (s.find(w) == std::string::npos) {
std::cout << "Word \"" << w << "\" does NOT exist in string s\n";
return false; // early exit if any word is missing
} else {
std::cout << "Word \"" << w << "\" exists in string s\n";
}
}
return true;
}
int main() {
std::string s = "efandabandcd";
std::vector<std::string> words = {"ab", "cd", "ef"};
if (allWordsExist(s, words)) {
std::cout << "All words exist in the string s\n";
} else {
std::cout << "Not all words exist in the string s\n";
}
}
/*
run:
Word "ab" exists in string s
Word "cd" exists in string s
Word "ef" exists in string s
All words exist in the string s
*/