Algorithm/COS
[COS Pro 1급, Python] 2차 9번 : 비밀번호 검사
JMcunst
2022. 2. 25. 10:37
728x90
반응형
문제 유형
한줄 수정
난이도
normal
Note
1. 연속된 3자리수 체크 하는 알고리즘. 연속된 x, y, z 문자 or 숫자가 있다면 y-x, z-y의 차이가 같아야 한다.
Code
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
# 2차 9번
def solution(password):
length = len(password)
for i in range(length - 2):
first_check = ord(password[i + 1]) - ord(password[i])
second_check = ord(password[i + 2]) - ord(password[i + 1])
if first_check == second_check and (first_check == 1 or first_check == -1):
return False
return True
password1 = "cospro890"
ret1 = solution(password1)
print("solution 함수의 반환 값은", ret1, "입니다.")
password2 = "cba323"
ret2 = solution(password2)
print("solution 함수의 반환 값은", ret2, "입니다.")
※ 가끔 코드 중 print(~)가 있습니다. 정리 못한 점 죄송합니다.
728x90
반응형