Problem:
Given a PAN card number, find whether number is valid or not.
Rule: Should follow format (UC)(UC)(UC)(UC)(UC)(D)(D)(D)(D)(UC)
where UC is upper case alphabet and D is digit
Rule: Should follow format (UC)(UC)(UC)(UC)(UC)(D)(D)(D)(D)(UC)
where UC is upper case alphabet and D is digit
Input Format:
n = no. of test cases
followed by n pancard numbers in different lines
followed by n pancard numbers in different lines
Output Format:
print "YES" for valid and "NO" for invalid
print "YES" for valid and "NO" for invalid
Constraints:
none
none
Sample Input
3
ABCDE1234F
ABCDe1234F
ABCDE12345
ABCDE1234F
ABCDe1234F
ABCDE12345
Sample Output:
YES
NO
NO
YES
NO
NO
Explanations:
for case 2, it contains lower case alphabet, so number is invalid
for case 2, it contains lower case alphabet, so number is invalid
Solution:
for($i=0;$i<$n;$i++)
{
chomp($s=<STDIN>);
if($s =~ /[A-Z][A-Z][A-Z][A-Z][A-Z]\d\d\d\d[A-Z]/)
{
push(@out,"YES");
}
else
{
push(@out,"NO");
}
}
foreach(@out)
{
print "$_\n";
}
Tips:
[A-Z] means any upper case alphabet
No comments:
Post a Comment