일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- Sequential Search
- til
- codesingal
- cpp
- centuryFromYear
- 파이썬 포렌식
- 피보나치 수
- collections.deque
- Daily Commit
- adjacentElementsProduct
- All Longest Strings
- C++
- almostIncreasingSequence
- codesignal
- 파이썬머신러닝완벽가이드
- flask
- 백준
- 2015 봄학기 알고리즘
- baekjun
- 수 정렬하기
- Numpy
- Counting cells in a blob
- 10953
- recursion
- matrixElementsSum
- shapeArea
- Python
- 2750
- data_structure
- markdown
Archives
- Today
- Total
Introfor
[백준] 5622번 다이얼 본문
단순히 조건문을 여러 개 써서 푸는 것과 아스키코드를 사용해서 푸는 것, 다이얼과 리스트의 관계를 통해서 푸는 방법이 있다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
def solution():
string = input()
time = 0
for s in string:
if ord(s) <= 67: time += 3
elif 68 <= ord(s) <= 70: time += 4
elif 71 <= ord(s) <= 73: time += 5
elif 74 <= ord(s) <= 76: time += 6
elif 77 <= ord(s) <= 79: time += 7
elif 80 <= ord(s) <= 83: time += 8
elif 84 <= ord(s) <= 86: time += 9
else: time += 10
return time
res = solution()
print(res)
|
cs |
다른 풀이(1)
1
2
3
4
5
6
7
8
9
10
11
|
def solution():
string = input()
time = [3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10]
res = 0
for s in string:
res += time[ord(s) - 65]
return res
res = solution()
print(res)
|
cs |
다른 풀이(2)
1 2 3 4 5 6 7 8 9 10 11 12 13 | def solution(): dial = ['ABC', 'DEF', 'GHI', 'JKL', 'MNO', 'PQRS', 'TUV', 'WXYZ'] string = input() res = 0 for i in range(len(string)): for j in dial: if string[i] in j: res += dial.index(j) + 3 return res res = solution() print(res) | cs |
Comments