dimanche 6 septembre 2020

I need clarification regarding condition checking [closed]

string decryptPassword(string s) {
        vector<char> v;
        string res;
        vector<char> r;
        long unsigned int i=0;
        while(s[i]>'0' && s[i]<='9')
        {
            v.push_back(s[i]);
            i++;
        }
        for(long unsigned int i=0;i<s.size();i++)
        {
            cout<<s[i];
        }
        cout<<endl;
        for(;i<s.size();i++)
        {
            if(isupper(s[i]) && islower(s[i+1] && s[i+2]=='*'))
            {
                r.push_back(s[i+1]);
                r.push_back(s[i]);
                i+=2;
            }
            else if(s[i]=='*')
                continue;
            else if(s[i]=='0')
            {
                r.push_back(v.back());
                v.pop_back();
            }
            else
            {
                r.push_back(s[i]);
            }
        }
        for(long unsigned int i=0;i<r.size();i++)
        {
            cout<<r[i];
            res.push_back(r[i]);
        }
        return res;
    }

Above is part of code where i used the condition

What is the difference between below two statements

s1:isupper(s[i]) && islower(s[i+1]) && s[i+2]=='*'

s2: s[i+2]=='*' && isupper(s[i]) && islower(s[i+1])

I have used both conditions in if statement, for example, if input is s="ab*" condition in s1 return false and s2 return true.

Why does this happen?

Aucun commentaire:

Enregistrer un commentaire