Introfor

[백준] 5622번 다이얼 본문

카테고리 없음

[백준] 5622번 다이얼

YongArtist 2020. 10. 6. 08:24

단순히 조건문을 여러 개 써서 푸는 것과 아스키코드를 사용해서 푸는 것, 다이얼과 리스트의 관계를 통해서 푸는 방법이 있다.

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 = [333444555666777888899910101010]
    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