Created
August 1, 2013 05:53
-
-
Save rfaisal/6128713 to your computer and use it in GitHub Desktop.
A new identification number is given for every Citizen of the Country Utopia and it has the following format. The string must begin with between 0 and 3 (inclusive) lowercase letters. Immediately following the letters, there must be a sequence of digits. The length of this segment must be between 2 and 8, both inclusive. Immediately following th…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class UtopianIdentificationNumber { | |
| public static boolean test(String s){ | |
| int stage=1; | |
| int count=0; | |
| for(int i=0;i<s.length();i++){ | |
| char c= s.charAt(i); | |
| if(stage==1){ | |
| if(!(c>='a' && c<='z')){ | |
| if((i-count)>=0 && (i-count)<=3){ | |
| count=i; | |
| stage=2; | |
| } | |
| else | |
| return false; | |
| } | |
| } | |
| if(stage==2){ | |
| if(!(c>='0' && c<='9')){ | |
| if((i-count)>=2 && (i-count)<=8){ | |
| count=i; | |
| stage=3; | |
| } | |
| else | |
| return false; | |
| } | |
| } | |
| if(stage==3){ | |
| if(!(c>='A' && c<='Z')){ | |
| return false; | |
| } | |
| } | |
| } | |
| if(stage==1 || stage==2 || s.length()-count<3) return false; | |
| return true; | |
| } | |
| public static void main(String[] args) { | |
| Scanner scanner = new Scanner( System.in ); | |
| int n=scanner.nextInt(); | |
| for(int i=0;i<n;i++){ | |
| String s=scanner.next(); | |
| if(test(s)) System.out.println("VALID"); | |
| else System.out.println("INVALID"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment