Created
November 13, 2018 18:02
-
-
Save david-mart/dda7b7ec303f70eed299074df9fb4da5 to your computer and use it in GitHub Desktop.
matchingCollections.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int arrayLength = 3; | |
int findMatchingCollections(std::string inputString, std::string collections[]) { | |
int matchCounter = 0; | |
for(int i = 0; i < arrayLength; i++) { | |
int collectionLength = collections[i].length(); | |
int j = 0; | |
bool allMatching = true; | |
while (allMatching && j < collectionLength) { | |
allMatching = inputString.find(collections[i][j]) != std::string::npos; | |
j++; | |
} | |
if(allMatching) { | |
matchCounter ++; | |
} | |
} | |
return matchCounter; | |
} | |
int main() { | |
std::string input = "Test input string"; | |
std::string collections[arrayLength] = {"Te", "pi", "ang"}; | |
int count = findMatchingCollections(input, collections); | |
std::cout << count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment