CamelCase pattern matching in C++

In this tutorial, we are going to discuss the CamelCase pattern matching in C++. Before moving towards CamelCase programming, first, we need to understand what is CamelCase?

CamelCase: In programming, term CamelCase can be stated as the style preferred by the programmer in which the first letter of every word is capitalized and all other letters are small, the words do not separate by white space. Such a type of writing style is referred to as CamelCase.

Some Examples of CamelCase words:

  • right one
  • Left one
  • HonestOne
  • LeftVariable
  • RightVariable

So we have learned some of the examples of the camelcase in the examples below. Now we are going to create a code for the CamelCase pattern matching in which we are going to match the given pattern with the input given and if the pattern matches, we are going to print it in the output of the program.

Code of Class for CamelCase pattern matching

class Solution {
public:
    bool check(string s,string pattern){
        int j =0;
        int i =0;
        for(char x: s){
            if(x>='A'&&x<='Z')
            {
                if(j<pattern.size())
                {
                    
                    if(x!=pattern[j])
                        return false;
                    else
                        j++;
                }
                else
                    return false
                
            }
            else
            {
                if(pattern[j]>='a'&&pattern[j]<='z')
                {
                    if(pattern[j]==x)
                        j++;
                }
            }
            
            
        }
        if(j!=pattern.size())
            return false;
        
        return true;
    }
    
    vector<bool> camelMatch(vector<string>& queries, string pattern) {
        vector<bool> ans ;
        for(string s:queries)
        {
            ans.push_back(check(s,pattern));
        }
        return ans;
    }
};
int main()
{
vector<string> queries;
string pattern="HT";
Solution a;
queries.push_back("HiTech");
queries.push_back("HiTechn0");
queries.push_back("Hit");
queries.push_back("hiTech");
queries.push_back("hitech");
if(a.check)
{
cout<<", "<<camelMatch(queries,pattern);
}
return 0;
}
Input: HiTech , HiTechno ,Hit ,hiTech,hitech
Output:HiTech, HiTechno

You can also be referred to:

Leave a Reply

Your email address will not be published. Required fields are marked *