T9 Spelling
This commit is contained in:
25
t9spelling.py
Normal file
25
t9spelling.py
Normal file
@@ -0,0 +1,25 @@
|
||||
t9 = {
|
||||
"a": "2", "b": "22", "c": "222", "d": "3", "e": "33", "f": "333",
|
||||
"g": "4","h": "44", "i": "444", "j": "5", "k": "55", "l": "555", "m": "6", "n": "66", "o": "666",
|
||||
"p": "7", "q": "77", "r": "777", "s": "7777", "t": "8", "u": "88", "v": "888", "w": "9", "x": "99", "y": "999", "z": "9999",
|
||||
" ": "0",
|
||||
}
|
||||
|
||||
n = int(input())
|
||||
outputs = []
|
||||
for i in range(n):
|
||||
message = input()
|
||||
prev_c = None
|
||||
for c in message:
|
||||
if prev_c is None:
|
||||
output = t9[c]
|
||||
else:
|
||||
if t9[c][0] == prev_c[0]:
|
||||
output = f"{output} {t9[c]}"
|
||||
else:
|
||||
output = f"{output}{t9[c]}"
|
||||
prev_c = t9[c]
|
||||
outputs.append(f"Case #{i+1}: {output}")
|
||||
|
||||
for out in outputs:
|
||||
print(out)
|
||||
Reference in New Issue
Block a user