28 October 2014

Quiz 42: Valid PAN card number verification

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

Input Format: 
n = no. of test cases
followed by n pancard numbers in different lines

Output Format: 
print "YES" for valid and "NO" for invalid

Constraints: 
none

Sample Input
3
ABCDE1234F
ABCDe1234F
ABCDE12345

Sample Output:
YES
NO
NO

Explanations:
for case 2, it contains lower case alphabet, so number is invalid


Solution:

chomp($n=<STDIN>);
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