Alien
Username
The following is the solution to the Hacker Rank problem “Alien Username" using Java.  For other Hacker Rank problem solutions visit my Hacker Rank Solutions Page.
/** 
 * @author Arun.G 
 * 
 */ 
import java.io.*; 
import java.util.*; 
import java.text.*; 
import java.math.*; 
import java.util.regex.*; 
public class Solution { 
    public static void main(String[]
  args) { 
        /* Enter your code here. Read input from
  STDIN. Print output to STDOUT. Your class should be named Solution. */ 
        Scanner sc = new Scanner(System.in); 
        int no = sc.nextInt(); 
        while(no-->=0) 
        { 
            String word = sc.nextLine(); 
            int count=0; 
            if(!word.equals("")) 
            { 
                //for country 
                String pattern ="^[._]{1}[0-9]{1,}[a-zA-Z]{0,}_{0,1}$"; 
                Pattern userNamePattern =
  Pattern.compile(pattern); 
                Matcher m =
  userNamePattern.matcher(word); 
                if(m.find()) 
                { 
                   System.out.println("VALID"); 
                } 
                else 
                { 
                    System.out.println("INVALID"); 
                } 
            } 
        } 
    } 
} 
 | 
 
No comments:
Post a Comment