fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. bool match(const string& query, const string& pattern) {
  6. int i = 0;
  7. for (char ch : query) {
  8. if (i < pattern.length() && ch == pattern[i]) {
  9. i++;
  10. } else if (isupper(ch)) {
  11. return false;
  12. }
  13. }
  14. return i == pattern.length();
  15. }
  16.  
  17. vector<bool> camelMatch(vector<string>& queries, string pattern) {
  18. vector<bool> result;
  19. for (const string& query : queries) {
  20. result.push_back(match(query, pattern));
  21. }
  22. return result;
  23. }
  24.  
  25. int main() {
  26. vector<string> queries = {"FooBar", "FooBaz", "FoBaT", "FootBall"};
  27. string pattern = "FoBa";
  28.  
  29. vector<bool> matches = camelMatch(queries, pattern);
  30.  
  31. for (bool res : matches) {
  32. cout << (res ? "true" : "false") << endl;
  33. }
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
true
true
false
true