WA on PASSWD problem

Hi,

Does anyone have any idea what’s wrong with my code? :thinking:

#include <iostream>
#include <string>

/*Problem Code: PASSWD 
author: akame9 */

using namespace std;

int main() {
	
	int test_cases;
	
	string str;

	bool rule1, rule2, rule3, rule4, rule5;
	
	cin >> test_cases;
	
	for(int i = 0; i < test_cases; i++){
	    
	    cin >> str;
	    
	    rule5 = 1;
	    
	    if(str.length() < 10) rule5 = 0; //Rule 5
	    
	    if(rule5 == 1){
	        
	        rule1 = rule2 = rule3 = rule4 = 0;
	        
	        if((str[0] >= 'a' && str[0] <= 'z') || (str[str.length()-1] >= 'a' && str[str.length()-1] <= 'z'))
	        rule1 = 1;
	        //(early check for rule1 (only lowercase letters count as "not strictly inside" one)).
	        
	        //Rules 1 to 4
	        
	        for(int j = 1; j < str.length()-1; j++){ //("j=1", "str.length()-1" for skipping first and last letter of the string).
	                                                 //(because for rules 2 to 4 only "strictly inside" characters count)
	            if(str[j] >= 'A' && str[j] <= 'Z') rule2 = 1;
	            else if(str[j] >= '0' && str[j] <= '9') rule3 = 1;
	            else if(str[j] == '@' || str[j] == '#' || str[j] == '%' || str[j] == '&' || str[j] == '?') rule4 = 1;
	            else if(str[j] >= 'a' && str[j] <= 'z') rule1 = 1;
	            
	        }
	        
	        
	    }
	    
	    if(rule1 == rule2 == rule3 == rule4 == rule5 == 1)
        cout << "YES\n";
        else
        cout << "NO\n";
	    
	}
	
	
	return 0;
}

Everything works fine on sample input (matching answers on my output) but doesn’t work on test cases from submisson.
Tried few of my own sample inputs and code worked fine too… I know it’s a pretty common topic but I have no idea what’s wrong and I thought maybe some of you would notice, any help will be appreciated : )

– > link to this problem

Thanks for any answers

Check the following update to your code.

Accepted