Sort by

recency

|

556 Discussions

|

  • + 0 comments

    I have used regex to solve this problem, and some python logics.

    I have created 3 differents patterns (1 for each condition, except the last one which check at the same time if the UID is exactly 10 characters).

    first condition pattern check if 2 uppercase (at least) are present or not.

    Note : ?. is a lookaround operators and it means anything before an uppercase. So "....A....". This format must be repeated at least twice : {2,}

    Exact same logics with digits 0-9

    And the last pattern, I think, is logic to understand, we only want a-zA-Z0-9 characters exactly 10 times.

    Then, we just have to check condition by condition.

    Here my code, I am pretty sure there is a simple way or more concise way to solve this problem, but, it works and the logics sounds good :

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import re
    
    T = int(input())
    
    UID_list = list()
    
    for _ in range(T):
        current_UID = input()
        UID_list.append(current_UID)
        
    # Patterns
    first_condition_pattern = r'^(?=(?:.*[A-Z]){2,}).*$'
    
    second_condition_pattern = r"^(?=(?:.*[0-9]){3,}).*$"
    
    third_condition_pattern = r"[a-zA-Z0-9]{10}"
    
    for element in UID_list:
        
        if len(set(element)) != len(list(element)):
            #print("Repeat character")
            print("Invalid")
    
        elif bool(re.match(first_condition_pattern, element)) == False:
            #print("Not 2 upper case minimum")
            print("Invalid")
        
        elif bool(re.match(second_condition_pattern, element)) == False:
            #print("Not 3 digits minimum")
            print("Invalid")
        
        elif bool(re.match(third_condition_pattern, element)) == False:
            #print("Not only alphanumeric character or not exactly 10 characters")
            print("Invalid")
        
        else:
            print("Valid")
    
  • + 0 comments
    N = int(input())
    
    
    l1 = []
    
    for i in range(N):
        inp = input()
        l1.append([ch for ch in inp])
    
    
    l2 = [set(item) for item in l1]
    
    
    upperCase = 0
    digits = 0
    
    for i in range(N):
        
        for ch in l1[i]:    
            if ch.isupper():
                upperCase+=1
            if ch.isdigit():
                digits += 1
                
        if all([len(l1[i]) == len(l2[i]) and len(l1[i])==10,upperCase>=2,digits>=3]):
            print("Valid")
        else:
            print("Invalid")
            
        upperCase = 0
        digits = 0
               
    
  • + 0 comments
    T= int(input())
    
    for _ in range(T):
        criteria = []
        user_id_str= input()
        user_id = [i for i in user_id_str]
        
        #1. At least 2 uppercase English alphabet 
        criteria.append((len([element.isupper() for element in user_id if element.isupper() is True])) >= 2)
        
        #2. At least 3 digits
        criteria.append((len([element.isdigit() for element in user_id if element.isdigit() is True])) >= 3)   
           
        #3. only contain alphanumeric
        criteria.append(user_id_str.isalnum())
        
        #4. No character should repeat
        criteria.append((len(user_id)) == (len(set(user_id))))
        
        #5. Must be exactly 10 characters 
        criteria.append(len(user_id) == 10)
        
        print("Valid" if all(criteria) else "Invalid")
       
            
            
    
  • + 0 comments

    import re

    uid = list T = int(input()) pattern = r'^(?=(?:.[A-Z]){2,})(?=(?:.\d){3,})[A-Za-z\d]+$'

    for _ in range(T): # print(T) id = input() if len(set(id))==10: if re.match(pattern, id): print("Valid") else: print("Invalid") else: print("Invalid")

  • + 0 comments
    import re
    n= int(input())
    valido =True
         
    for _ in range(n):
        UID =input();
        if len(UID)==10:
            valido = True
        else:
            valido =False
        
        if valido  and UID.isalnum():
            valido =True
        else:
            valido = False
        if valido and len(re.findall(r'[A-Z]',UID))>=2:
            valido = True
        else:
            valido =False
        if valido and len(re.findall(r'[0-9]',UID))>=3:
            valido = True
        else:
            valido =False
        
        for c in UID:
            if len(re.findall(c,UID))!=1:
                valido=False
                break
            
            
        print("Valid" if valido else "Invalid")