Strong Password

  • + 0 comments

    c++

    int minimumNumber(int n, string password) {
        // Return the minimum number of characters to make the password strong
        int d = 0, l = 0, u = 0, s = 0;
        
        for (const char& c : password)
        {
            if (c >= '0' && c <= '9')
                ++d;
            else if (c >= 'a' && c <= 'z')
                ++l;
            else if (c >= 'A' && c <= 'Z')
                ++u;
            else
                ++s;
        }
        
        int r = 0;
        
        if (d == 0)
            ++r;
            
        if (l == 0)
            ++r;
            
        if (u == 0)
            ++r;
            
        if (s == 0)
            ++r;
            
        return max(6 - n, r);
    }