[python]白駿5622号:ダイヤル
Problem
https://www.acmicpc.net/problem/5622
Solution
code 1
code 2
Comment
Ref
https://j-remind.tistory.com/76
https://www.acmicpc.net/problem/5622
Solution
code 1
def dial_time(letter):
if 'A'<=letter<='C':
return 3
elif 'D'<=letter<='F':
return 4
elif 'G'<=letter<='I':
return 5
elif 'J'<=letter<='L':
return 6
elif 'M'<=letter<='O':
return 7
elif 'P'<=letter<='S':
return 8
elif 'T'<=letter<='V':
return 9
elif 'W'<=letter<='Z':
return 10
total_time = 0
dial_word = input()
for i in dial_word:
total_time += dial_time(i)
print(total_time)
1つ目の方法は、各文字をif文に分割し、戻り時間の関数を定義することです.code 2
dial_list = ['ABC', 'DEF', 'GHI', 'JKL', 'MNO', 'PQRS', 'TUV', 'WXYZ']
a = input()
total_time = 0
for j in a:
for i in range(len(dial_list)):
if j in dial_list[i]:
total_time += i+3
print(total_time)
2つ目の方法は、リストを使用する方法です.各番号に対応する時間は等差数列であるため,効果的に解決できる.Comment
Ref
https://j-remind.tistory.com/76
Reference
この問題について([python]白駿5622号:ダイヤル), 我々は、より多くの情報をここで見つけました https://velog.io/@23tae/Python-백준-5622번-다이얼テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol