# https://www.hackerrank.com/contests/hourrank-24/challenges/strong-password # read input from HackerRank def read_input(): '''The first line contains an integer n denoting the length of the string. The second line contains a string consisting of n characters, the password typed by Louise. Each character is either a lowercase/uppercase English alphabet, a digit, or a special character. ''' n = int(input()) chars = input() return n, chars def make_strong(str_, numbers, lower, upper, special): ''' Make the input str_ strong using a minimum number of chars It is strong if: Its length is at least 6. It contains at least one digit. It contains at least one lowercase English character. It contains at least one uppercase English character. It contains at least one special character. The special characters are: !@#$%^&*()-+ ''' count = 0 at_least_one_digit = False at_least_one_lower = False at_least_one_upper = False at_least_one_special = False if len(str_) == 0: # Add a digit str_ += '0' count += 1 else: for char in str_: if char in numbers: at_least_one_digit = True if char in lower: at_least_one_lower = True if char in upper: at_least_one_upper = True if char in special: at_least_one_special = True if at_least_one_digit != True: # Add a digit: str_ += '0' count += 1 if at_least_one_lower != True: # Add a lowercase letter str_ += 'a' count += 1 if at_least_one_upper != True: str_ += 'A' count += 1 if at_least_one_special != True: str_ += '!' count += 1 if len(str_) < 6: chars_left = 6 - len(str_) str_ +=''.join(['a' for x in range(chars_left)]) count += chars_left return count def main(): numbers = "0123456789" lower_case = "abcdefghijklmnopqrstuvwxyz" upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" special_characters = "!@#$%^&*()-+" n, str_ = read_input() count_changes = make_strong(str_, numbers, lower_case, upper_case, special_characters) print(count_changes) main()