[Hackerrank] Strong Password

이재윤·2025년 2월 11일

https://www.hackerrank.com/challenges/strong-password/submissions/code/419910089

1) 코드

#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'minimumNumber' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
#  1. INTEGER n
#  2. STRING password
#

def minimumNumber(n, password):
    
    answer = 0
    curr = n
    FalseCnt = 0

    numbers = "0123456789"
    lower_case = "abcdefghijklmnopqrstuvwxyz"
    upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    special_characters = "!@#$%^&*()-+"

    num = False
    low = False
    up = False
    special = False

    for c in password:
        if c in numbers:
            num = True
        elif c in lower_case:
            low = True
        elif c in upper_case:
            up = True
        elif c in special_characters:
            special = True

    if num == False:
        FalseCnt += 1
    if low == False:
        FalseCnt += 1
    if up == False:
        FalseCnt += 1
    if special == False:
        FalseCnt += 1

    n += FalseCnt
    answer += FalseCnt

    if n>= 6:
        return answer
    else:
        answer += (6-n)
        return answer
    
    # Return the minimum number of characters to make the password strong

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input().strip())

    password = input()

    answer = minimumNumber(n, password)

    fptr.write(str(answer) + '\n')

    fptr.close()

0개의 댓글