Skip to content

Instantly share code, notes, and snippets.

@david-mart
Created November 13, 2018 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-mart/dda7b7ec303f70eed299074df9fb4da5 to your computer and use it in GitHub Desktop.
Save david-mart/dda7b7ec303f70eed299074df9fb4da5 to your computer and use it in GitHub Desktop.
matchingCollections.cpp
#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