Password---Jan Cook Off

/**
import re
m=int(input())
for j in range(m):
password=str(input())
flag=1
while True:
if (len(password)<10):
flag = -1
break
elif not re.search(“[a-z]”, password[0]):
flag = -1
break
elif not re.search(“[a-z]”, password[-1]):
flag = -1
break
elif not re.search(“[a-z]”, password):
flag = -1
break
elif not re.search(“[A-Z]”, password[1:len(password)-1]):
flag = -1
break
elif not re.search(“[0-9]”, password[1:len(password)-1]):
flag = -1
break
elif not re.search(“[@#%&?]”, password[1:len(password)-1]):
flag = -1
break
else:
flag = 0
print(“YES”)
break

if flag ==-1: 
    print("NO") 

**/

any idea what is wrong with my solution?

Why are you doing these? Where does it say that the first and last element of password must be lowercase characters? see 2nd sample test case

I tried even like this (re.search("[a-z]", password[0]) or re.search("[A-Z]", password[0])) but it gave wrong answer.

It must contain at least one upper case letter [A-Z], strictly inside it–> this condition says that it should be only inside right ?

The condition says at least one should be inside.
It does not mean that all occurences must be inside.

I have modified your solution: CodeChef: Practical coding for everyone

1 Like

@cubercoder thank you :smiley:. I understood now.

1 Like

No,it says that there should be atleast one upper case letter[A-Z] which is strictly inside. It can be on first and last but should also be inside too.

1 Like

i think the test cases that is already there are incorrect .
like for U@code4CHEFINA this test case they said it’s valid pass . and according to condition no.2 that is " Password must contain at least one upper case letter [A−Z] strictly inside, i.e. not as the first or the last character;" we should print “no” then how they said it’s valid pass. becoz at first pos there is U and A on the last . please help me out with this

Hello,

At least one character A-Z is strictly inside as well.
It does not mean that all A-Z characters must be strictly inside.

Bro, test cases are correct. The question says that password must contain atleast one upper case letters which is inside. It doesnt mean that upper case letters cant be on first or last, they can be but atleast one should be inside.

Bro! It’s not mentioned anywhere that the first & last digits of the string input have to be a lowercase character. Also, the explanation regarding strictly inside was not so lucid, however, it can be solved easily using regex. You can check my solution below:
import re
for T in range(int(input().strip())):
S=input()
S1=S[1:-1]
if (len(S)>=10):
x=re.findall(“[0-9]”, S1)
y=re.findall(“[A-Z]”, S1)
z=re.findall(“[@,#,%,?,&]”, S1)
w=re.findall(“[a-z]”, S)
if x and y and z and w:
print(“YES”)
else:
print(“NO”)
else:
print(“NO”)

https://www.codechef.com/viewsolution/41854555

1 Like