Sort by

recency

|

130 Discussions

|

  • + 0 comments

    Using typescript:

    'use strict';
    
    process.stdin.resume();
    process.stdin.setEncoding('utf-8');
    let inputString: string = '';
    let inputLines: string[] = [];
    let currentLine: number = 0;
    process.stdin.on('data', function(inputStdin: string): void {
        inputString += inputStdin;
    });
    
    process.stdin.on('end', function(): void {
        inputLines = inputString.split('\n');
        inputString = '';
        main();
    });
    
    function readLine(): string {
        return inputLines[currentLine++];
    }
    
    function main() {
        // Enter your code here
        const regex = /(^[\_\.]\d+[a-zA-Z]*\_?$)|(^[\_\.]\d+$)/;
        for(let i=1; i<inputLines.length; i++) {
            if(inputLines[i].match(regex)) {
                console.log("VALID")
            } else {
                console.log("INVALID")
            }
        }
    }
    
  • + 0 comments
       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();
       sc.nextLine();
       
       
       String regex = "^[_\\.](?<=[_\\.])\\d+[a-zA-Z]*_?";
       Pattern p = Pattern.compile(regex);
       
       
       for (int i = 0; i<no; i++){
        String s = sc.nextLine();
    
       if(p.matcher(s).matches()){
    
        System.out.println("VALID");
        
       }
       else{
        System.out.println("INVALID");
       }
        }
    
  • + 0 comments
    import re
    pattern=r"^[\.\_]{1}[0-9]{1,}[a-zA-Z]*[\_]?$"
    for _ in range(int(input())):
        if re.match(pattern,input()):
            print("VALID")
        else:
            print("INVALID")
    
  • + 0 comments

    In Python 3:

    N = int(input())
    alien_name = r'^(_|\.)[0-9]{1,}[a-zA-Z]{0,}(_)?$'
    for _ in range(N):
        name = input()
        matched = re.match(alien_name, name)
        if bool(matched):
            print("VALID")
        else:
            print("INVALID")
    
  • + 0 comments

    import re n = int(input()) for _ in range(n): username = input() pattern = r'^[.]\d{1,}[a-zA-Z]*[]?$' if re.search(pattern,username): print("VALID") else: print("INVALID")