Sort by

recency

|

535 Discussions

|

  • + 0 comments

    python3

    import re
    t = int(input())
    
    # this relies on greedy nature of positive and negative lookahead
    reg = re.compile(r'''
        (?=.*[A-Z].*[A-Z].*)     # at least two uppercase alphabets
        (?=.*[0-9].*[0-9].*[0-9].*) # at least three digits
        (?=\w{10})          # only ten alphanumeric characters in total
        (?!.*(.).*\1.*)         # no repetition of the same characters
        ''', re.VERBOSE)
    
    for i in range(t):
        if reg.match(input().strip()):
            print("Valid")
        else:
            print("Invalid")
    
  • + 0 comments

    number = int(input())

    for _ in range(number): UID = input() UID_list = list(UID)

    upper_count = 0
    digit_count = 0   
    duplicate = False
    lower_flag = False
    
    UID_dic = dict.fromkeys(UID_list,0) 
    
    for i in UID_list:
        if UID.isalnum() and len(UID) == 10 :     
                if i.isupper():
                    upper_count = upper_count+1   
                    UID_dic[i] = UID_dic[i] +1
                if i in ["0","1","2","3","4","5","6","7","8","9"]:
                    digit_count = digit_count+1
                    UID_dic[i] = UID_dic[i] +1
                if i.islower():
                    lower_flag = True
                    UID_dic[i] = UID_dic[i] +1
    
    for i in UID_list:
        if UID_dic[i] > 1:
           duplicate = True
           break
    
    if duplicate or upper_count < 2 or digit_count < 3 :
      print("Invalid")   
    else:
      print("Valid")
    
  • + 1 comment
    import sys, re
    
    T = sys.stdin.read().splitlines()
    T = [T[1:] if len(T)<90 else T[1:91]][0]
    
    UID = re.compile(
        r"(?!.*(.).*\1)"
        r"(?=^[a-zA-Z0-9]{10}$)"
        r"(?=(.*[A-Z].*){2,})"
        r"(?=(.*\d.*){3,})"
    )
    
    for line in T:
        if UID.search(line):
            print('Valid')
        else:
            print('Invalid')
    
  • + 0 comments

    test_cases = int(input()) for i in range(test_cases): string = input() upper_count=0 digits_count=0 for ele in string: if ele.isupper(): upper_count += 1 elif ele.isdigit(): digits_count += 1
    unique_count = len(string)==len(set(string)) if len(string)==10 and unique_count and string.isalnum() and upper_count >=2 and digits_count >= 3: print('Valid') else: print('Invalid')

    
    
  • + 1 comment
    from collections import Counter
    
    def validate(txt):
    
        #It must contain at least 2 uppercase English alphabet characters
        if sum([1 for x in txt if x.isupper()]) < 2:
            return False
    
        #It must contain at least 3 digits
        if sum([1 for x in txt if x.isdigit()]) < 3:
            return False
            
        #It should only contain alphanumeric characters 
        if not txt.isalnum():
            return False
    
        #No character should repeat.
        if (any(value != 1 for value in Counter(txt).values())):        
            return False
    
        #There must be exactly 10 characters in a valid UID.        
        if len(txt) != 10:
            return False
    
        
        return True
    
    n = int(input())
    for _ in range(n):
        txt = input().strip()
        print("Valid") if validate(txt) else  print("Invalid")