Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Vue
- 파이썬
- 안드로이드
- 개발
- 코딩테스트
- cos pro
- 백준
- Flutter
- issue
- Algorithm
- android
- 분할정복
- 동적계획법
- codingtest
- django
- 알고리즘
- 안드로이드스튜디오
- cos
- DFS
- vuejs
- BAEKJOON
- C++
- 코드품앗이
- cos pro 1급
- Python
- AndroidStudio
- DART
- DFS와BFS
- 동적계획법과최단거리역추적
- 코테
Archives
- Today
- Total
Development Artist
[COS Pro 1급, Python] 2차 9번 : 비밀번호 검사 본문
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
반응형
'Algorithm > COS' 카테고리의 다른 글
[COS Pro 1급, Python] 3차 1번 : 배열을 회전시켜보세요 (0) | 2022.02.25 |
---|---|
[COS Pro 1급, Python] 2차 10번 : 0들을 0으로 만들기 (0) | 2022.02.25 |
[COS Pro 1급, Python] 2차 8번 : 규칙에 맞는 배열 구하기 (0) | 2022.02.25 |
[COS Pro 1급, Python] 2차 7번 : 거스름돈 구하기 (0) | 2022.02.25 |
[COS Pro 1급, Python] 2차 6번 : 로봇을 움직여주세요 (0) | 2022.02.25 |
Comments