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 | 29 | 30 |
Tags
- javascript
- group by
- 동적계획법
- Baekjoon
- dfs
- 프로그래머스
- 소프티어
- programmers
- 너비 우선 탐색
- 자바스크립트
- Python
- Java
- 티스토리챌린지
- SQL
- Dynamic Programming
- 파이썬
- 백준
- bfs
- Lv. 1
- Lv. 2
- 오블완
- Lv. 0
- DP
- SQL 고득점 KIT
- LEVEL 2
- join
- Lv. 3
- level 3
- softeer
- 깊이 우선 탐색
Archives
- Today
- Total
몸과 마음이 건전한 SW 개발자
프로그래머스 Lv. 1 시저 암호 Python 본문
728x90
문제 링크
https://school.programmers.co.kr/tryouts/72052/challenges
정답 코드
def solution(s, n):
answer = ''
# print(ord("a"), ord("z")) 97 122
# print(ord("A"), ord("Z")) 65 90
for a in s:
if a == " ":
answer += " "
else:
if a.isupper():
location = (ord(a) - 65 + n) % 26 + 65
answer += chr(location)
else:
location = (ord(a) - 97 + n) % 26 + 97
answer += chr(location)
return answer
풀이 방법
- ord와 chr 활용
느낀점
- 오랜만에 ord와 chr을 사용하려니 기억이 잘 나지 않았다.
728x90
'알고리즘' 카테고리의 다른 글
프로그래머스 Lv. 2 짝지어 제거하기 Python (0) | 2024.01.08 |
---|---|
프로그래머스 Lv. 1 이상한 문자 만들기 Python (2) | 2024.01.04 |
프로그래머스 Lv. 2 행렬의 곱 Python (0) | 2024.01.03 |
프로그래머스 Lv. 2 거리두기 확인하기 Python [반례 포함] (0) | 2024.01.03 |
프로그래머스 Lv. 2 삼각 달팽이 Python (0) | 2024.01.03 |