diff --git a/2942. Find Words Containing Character.cpp b/2942. Find Words Containing Character.cpp new file mode 100644 index 0000000..7be9a06 --- /dev/null +++ b/2942. Find Words Containing Character.cpp @@ -0,0 +1,26 @@ +#include +#include +#include + +using namespace std; + +vector findWordsContainingChar(const vector& words, char targetChar) { + vector result; + for (const string& word : words) { + if (word.find(targetChar) != string::npos) { + result.push_back(word); + } + } + return result; +} + +int main() { + vector words = {"apple", "banana", "cherry", "date"}; + char targetChar = 'a'; + vector filteredWords = findWordsContainingChar(words, targetChar); + cout << "Words containing '" << targetChar << "':\n"; + for (const string& word : filteredWords) { + cout << word << endl; + } + return 0; +}