Problem:


		
Problem A: Keitai Message

		

			Alice さんは Miku さんに携帯電話でメールを送ろうとしている。
		

		

			携帯電話には入力に使えるボタンは数字のボタンしかない。 そこで、文字の入力をするために数字ボタンを何度か押して文字の入力を行う。携帯電話の数字ボタンには、次の文字が割り当てられており、ボタン 0 は確定ボタンが割り当てられている。この携帯電話では 1 文字の入力が終わったら必ず確定ボタンを押すことになっている。
		

1: . , ! ? (スペース)

2: a b c

3: d e f

4: g h i

5: j k l

6: m n o

7: p q r s

8: t u v

9: w x y z

0: 確定ボタン

		

			例えば、ボタン 2、ボタン 2、ボタン 0 と押すと、文字が 'a' → 'b' と変化し、ここで確定ボタンが押されるので、文字 b が出力される。
			同じ数字を続けて入力すると変化する文字はループする。すなわち、ボタン 2 を 5 回押して、次にボタン 0 を押すと、文字が 'a' → 'b' → 'c' → 'a' → 'b' と変化し、ここで確定ボタンを押されるから 'b' が出力される。
		

		

			何もボタンが押されていないときに確定ボタンを押すことはできるが、その場合には何も文字は出力されない。
		

		

			あなたの仕事は、Alice さんが押したボタンの列から、Alice さんが作ったメッセージを再現することである。
		

		
Input

		

			最初の行にテストケースの数が与えられる。 続いて各テストケースについて、最大で長さ 1024 の数字列が1行で与えられる。
		

		
Output

		

			Alice さんが作ったメッセージの文字列をそれぞれのテストケースについて 1 行ごとに出力せよ。
			ただし、出力は 1 文字以上 76 文字未満であると仮定してよい。
		

		
Sample Input

		

5
20
220
222220
44033055505550666011011111090666077705550301110
000555555550000330000444000080000200004440000

		
Output for the Sample Input

		

a
b
b
hello, world!
keitai



Sample input:
5
20
220
222220
44033055505550666011011111090666077705550301110
000555555550000330000444000080000200004440000


Sample output:
a
b
b
hello, world!
keitai

Submission status: Accepted

Solution code:
def moji(x,ans):
    if ans == 0:
        return
    if x == 1:
        if(ans%5==1):
            str = '.'
        elif(ans%5==2):
            str =','
        elif(ans%5==3):
            str='!'
        elif ans%5==4:
            str='?'
        else:
            str = ' '
    if x == 2:
        if(ans%3==1):
            str = 'a'
        elif(ans%3==2):
            str = 'b'
        else:
            str = 'c'
    if x == 3:
        if(ans%3==1):
            str = 'd'
        elif(ans%3==2):
            str = 'e'
        else:
            str = 'f'
    if x == 4:
        if(ans%3==1):
            str = 'g'
        elif(ans%3==2):
            str = 'h'
        else:
            str = 'i'
    if x == 5:
        if(ans%3==1):
            str = 'j'
        elif(ans%3==2):
            str = 'k'
        else:
            str = 'l'
    if x == 6:
        if(ans%3==1):
            str = 'm'
        elif(ans%3==2):
            str = 'n'
        else:
            str = 'o'
    if x == 7:
        if(ans%4==1):
            str = 'p'
        elif(ans%4==2):
            str = 'q'
        elif(ans%4==3):
            str ='r'
        else:
            str = 's'
    if x == 8:
        if(ans%3==1):
            str = 't'
        elif(ans%3==2):
            str = 'u'
        else:
            str = 'v'
    if x == 9:
        if(ans%4==1):
            str = 'w'
        elif(ans%4==2):
            str = 'x'
        elif ans%4==3:
            str = 'y'
        else:
            str = 'z'
    print(str,end="")
def solve(str):
    x = '-1'
    ans =0
    for s in str:
        if s == '0':
            moji(int(x),ans)
            ans = 0
        else:
            x = s
            ans +=1

N = int(input())
for i in range(N):
    solve(input())
    print()

Submission status: Accepted

Solution code:
# AOJ 2006: Keitai Message
# Python3 2018.6.20 bal4u

tbl = [0, ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]

for _ in range(int(input())):
	ans = []
	s, i = list(input()), 0
	while i < len(s):
		if s[i] != '0':
			id, k = int(s[i]), 0
			i += 1
			while s[i] != '0':
				i += 1
				k += 1
			ans.append(tbl[id][k % len(tbl[id])]);
		i += 1
	print(*ans, sep='')

Submission status: Accepted

Solution code:
a = ["" for i in range(10)]
a[1] = ".,!? "
a[2] = "abc"
a[3] = "def"
a[4] = "ghi"
a[5] = "jkl"
a[6] = "mno"
a[7] = "pqrs"
a[8] = "tuv"
a[9] = "wxyz"
num = int(input())
for count in range(num):
    s = input()
    b = ""
    c = '0'
    d = 0
    for i in s:
        if i=='0' :
            if c=='0': continue
            if c == '1':
                b += a[int(c)][d%5]
            elif c in "79":
                b += a[int(c)][d%4]
            else :
                b += a[int(c)][d%3]
            c = '0'
            d = 0
        if(c!=i):
            c = i
            d = 0
        else :
            d += 1
    print(b)

Submission status: Accepted

Solution code:
n = int(input())
string = ["", ".,!? ", "abc", "def", "ghi",
          "jkl", "mno", "pqrs", "tuv", "wxyz"]
for i in range(n):
    s = input()
    count = 0
    num = int(s[0])
    for c, c1 in zip(s, s[1:]):
        if c == c1:
            count += 1
        else:
            if num != 0:
                print(string[num][count % len(string[num])], end="")
            else:
                pass
            num = int(c1)
            count = 0
    print()

Submission status: Accepted

Solution code:
from itertools import cycle as c

n=int(input())
for _ in range(n):
  t=input()
  l=[]
  bf=""
  for nn in map(int,t):
    if not nn:
      l.extend([bf])
      bf=""
      continue
    if not bf:
      if nn:
        kl=[
          c(".,!? "),
          c("abc"),
          c("def"),
          c("ghi"),
          c("jkl"),
          c("mno"),
          c("pqrs"),
          c("tuv"),
          c("wxyz")
        ]
        bf=next(kl[nn-1])
    else:
      bf=next(kl[nn-1])
  print("".join(l))

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in xrange(n):
    msg = raw_input()
    tmp = ''
    c = -1
    ans = ''
    table = [[],
             ['.', ',', '!', '?', ' '],
             ['a', 'b', 'c'],
             ['d', 'e', 'f'],
             ['g', 'h', 'i'],
             ['j', 'k', 'l'],
             ['m', 'n', 'o'],
             ['p', 'q', 'r', 's'],
             ['t', 'u', 'v'],
             ['w', 'x', 'y', 'z']]
    for j in xrange(len(msg)):
        if msg[j] == '0':
            if c > -1:
                if msg[j-1] == '1':
                    ans += table[int(msg[j-1])][c%5]
                elif msg[j-1] == '7' or msg[j-1] == '9':
                    ans += table[int(msg[j-1])][c%4]
                else:
                    ans += table[int(msg[j-1])][c%3]
                c = -1
        else:
            tmp = msg[j]
            c += 1
    print ans

Submission status: Accepted

Solution code:
import sys

raw_input()

key = ['.,!? ', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz']

for line in sys.stdin:
    state = -1
    line = line.strip()
    result = ''
    count = 0
    for c in line:
        c = int(c) - 1
        if c == -1 and state != -1:
            result += key[state][count % len(key[state])]
            state = -1
        elif state == c:
            count += 1
        else:
            state = c
            count = 0
    print result

Submission status: Accepted

Solution code:
d={"1": ('.', ',', '!', '?', ' '), "2": ('a', 'b', 'c'), "3": ('d', 'e', 'f'), \
"4": ('g', 'h', 'i'), "5": ('j', 'k', 'l'), "6": ('m', 'n', 'o'), "7": ('p', 'q\
', 'r', 's'), "8": ('t', 'u', 'v'), "9": ('w', 'x', 'y', 'z')}
n=input()
for j in range(n):
    s=raw_input().split('0')
    print "".join([d[i[0]][(len(i)-1)%len(d[i[0]])] for i in s if i!=""])

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import groupby

a = ['_','.,!? ','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
for i in xrange(input()):
	b = [[i for i in j] for i,j in groupby(raw_input())]
	c = []
	d = ''
	for i in b:
		index = int(i[0])
		s = a[index][(len(i))%len(a[index])-1]
		if s == '_':
			d = d + ''.join(c)
			c = []
		else:
			c.append(s)
	if d != '':
		print d

Submission status: Accepted

Solution code:
from itertools import groupby

a = ['_','.,!? ','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
for i in xrange(input()):
	b = [[i for i in j] for i,j in groupby(raw_input())]
	c = []
	d = ''
	for i in b:
		index = int(i[0])
		s = a[index][(len(i))%len(a[index])-1]
		if s == '_':
			d = d + ''.join(c)
			c = []
		else:
			c.append(s)
	if d != '':
		print d

Submission status: Accepted

Solution code:
from itertools import groupby

a = ['_','.,!? ','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
for i in xrange(input()):
	b = [[i for i in j] for i,j in groupby(raw_input())]
	c = []
	d = ''
	for i in b:
		index = int(i[0])
		s = a[index][(len(i))%len(a[index])-1]
		if s == '_':
			d = d + ''.join(c)
			c = []
		else:
			c.append(s)
	print d

Submission status: Accepted

Solution code:
import itertools

t = ('.,!? ','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz')

for i in range(int(raw_input())):
    r = ''
    for i,j in itertools.groupby(raw_input()):
        j = ''.join(j)
        if i != '0':
            r += t[int(i) - 1][(len(j) - 1) % len(t[int(i) - 1])]
    print r

Submission status: Accepted

Solution code:
dic = {"1": ".,!? ", "2": "abc", "3": "def", "4": "ghi", "5": "jkl",
       "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz"}

for _ in xrange(input()):
    L = raw_input().split("0")
    print "".join(dic[s[0]][(len(s)-1)%len(dic[s[0]])] for s in L if not s == "")

Submission status: Accepted

Solution code:
import sys

litter = [""]
litter.append(list(" .,!? "))
litter.append(list(" abc"))
litter.append(list(" def"))
litter.append(list(" ghi"))
litter.append(list(" jkl"))
litter.append(list(" mno"))
litter.append(list(" pqrs"))
litter.append(list(" tuv"))
litter.append(list(" wxyz"))

n = input()
for count in range(n):
    ls = map(int, list(raw_input()))
    button, times = None, 0
    for i in ls:
        if i==0 :
            if button != None:
                sys.stdout.write(litter[button][times])
                button, times = None, 0
        else:
            button, times = i, times+1
            if times == len(litter[button]):
                times = 1
    sys.stdout.write('\n')

Submission status: Accepted

Solution code:
ref = {"1":[".",",","!","?"," "],
	   "2":["a","b","c"],
	   "3":["d","e","f"],
	   "4":["g","h","i"],
	   "5":["j","k","l"],
	   "6":["m","n","o"],
	   "7":["p","q","r","s"],
	   "8":["t","u","v"],
	   "9":["w","x","y","z"]}
for _ in range(input()):
	inputs = map(str,raw_input().split("0"))
	ans = ""
	for input in inputs:
		if len(input) > 0:
			ans += ref[input[0]][(len(input)-1)%len(ref[input[0]])]
	print ans

Submission status: Accepted

Solution code:
ref = {"1":".,!? ",
	   "2":"abc",
	   "3":"def",
	   "4":"ghi",
	   "5":"jkl",
	   "6":"mno",
	   "7":"pqrs",
	   "8":"tuv",
	   "9":"wxyz"}
for _ in range(input()):
	inputs = map(str,raw_input().split("0"))
	ans = ""
	for input in inputs:
		if len(input) > 0:
			k = input[0]
			ans += ref[k][(len(input)-1)%len(ref[k])]
	print ans

Submission status: Accepted

Solution code:
phone = [[], [".", ",", "!", "?", " "], ["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"], ["j", "k", "l"], 
         ["m", "n", "o"], ["p", "q", "r", "s"], ["t", "u", "v"], ["w", "x", "y", "z"]]

n = int(input())
for i in range(n) :
    message = list(input().split("0"))
    for j in range(len(message)) :
        if message[j] != "" :
            push = list(message[j])
            num = int(push[0])
            kaisuu = len(push) % len(phone[num])
            if kaisuu == 0 :
                print(phone[num][-1], end="")
            else :
                print(phone[num][kaisuu-1], end="")
    print()

Submission status: Accepted

Solution code:

keymap = [
    [".",",","!","?"," "],
    ["a","b","c"],
    ["d","e","f"],
    ["g","h","i"],
    ["j","k","l"],
    ["m","n","o"],
    ["p","q","r","s"],
    ["t","u","v"],
    ["w","x","y","z"]
]

n = int(input())

for i in range(n):
    keys = str(input())
    message = ""
    currentChar = ""
    currentKey = "X"
    push_counter = 0
    for key in keys:
        if key == "0":
            message += currentChar
            currentChar = ""
            currentKey = "0"
            continue
        if currentKey == key:
            push_counter += 1
        else:
            push_counter = 0
            currentKey = key
        key_int = int(currentKey) - 1
        count = push_counter % len(keymap[key_int])
        currentChar = keymap[key_int][count]
    print(message)

Submission status: Accepted

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    buttons = {
            '1': ".,!? ",
            '2': "abc",
            '3': "def",
            '4': "ghi",
            '5': "jkl",
            '6': "mno",
            '7': "pqrs",
            '8': "tuv",
            '9': "wxyz",
            }
    
    n = int(f_i.readline())
    
    ans = ""
    
    for i in range(n):
        code = f_i.readline().rstrip().split('0')
        
        for c in filter(lambda x: x != '', code):
            btn_chars = buttons[c[0]]
            idx = (len(c) - 1) % len(btn_chars)
            ans += btn_chars[idx]
            
        ans += '\n'
        
    print(ans, end='')

solve()

Submission status: Accepted

Solution code:
lists = [[".",",","!","?"," "],["a","b","c"],["d","e","f"],["g","h","i"],["j","k","l"],["m","n","o"],["p","q","r","s"],["t","u","v"],["w","x","y","z"]]
cnt = 0
moji = []
ans = []
n = int(input())
for k in range(n):
    s = str(input())
    for i in range(len(s)):
        if s[i] != "0":
            cnt += 1
            tmp = int(s[i])
            if cnt > len(lists[tmp-1]):
                cnt = cnt - len(lists[tmp-1]) 
            
        elif s[i] == "0" and cnt != 0:
                moji.append(lists[tmp - 1][int(cnt)-1])
                cnt = 0
    mojimoji = "".join(moji)
    ans.append(mojimoji)
    moji = []
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
tel_dict = {
        1 : (".", ",", "!", "?", " "),
        2 : ("a", "b", "c"),
        3 : ("d", "e", "f"),
        4 : ("g", "h", "i"),
        5 : ("j", "k", "l"),
        6 : ("m", "n", "o"),
        7 : ("p", "q", "r", "s"),
        8 : ("t", "u", "v"),
        9 : ("w", "x", "y", "z"),
        }
def get_input():
    input_data = input()
    return input_data

def convert_num_to_word(num_str):
    count = 0
    c_list = list()
    for i in num_str:
        if i != "0":
            num_state = int(i)
            count += 1
        else:
            if count == 0:
                continue
            order = (count - 1) % len(tel_dict[num_state])
            # print("order", order) # debug
            c = tel_dict[num_state][order]
            c_list.append(c)
            count = 0 # reset
    return c_list




if __name__ == "__main__":
    input_data = int(get_input())
    for i in range(input_data):
        input_data = get_input()
        c_list = convert_num_to_word(input_data)
        word = "".join(c_list)
        print(word)

Submission status: Accepted

Solution code:
keylist = [
   [],
   ['.', ',', '!', '?', ' '],
   ['a', 'b', 'c'],
   ['d', 'e', 'f'],
   ['g', 'h', 'i'],
   ['j', 'k', 'l'],
   ['m', 'n', 'o'],
   ['p', 'q', 'r', 's'],
   ['t', 'u', 'v'],
   ['w', 'x', 'y', 'z']
]
for i in range(int(input())):
   output = ''
   for item in input().split('0'):
      if item == '':
         continue
      output += keylist[int(item[0])][len(item) % len(keylist[int(item[0])]) - 1]
   print(output)

Submission status: Accepted

Solution code:
keys = {
    '1': '.,!? ',
    '2': 'abc',
    '3': 'def',
    '4': 'ghi',
    '5': 'jkl',
    '6': 'mno',
    '7': 'pqrs',
    '8': 'tuv',
    '9': 'wxyz',
}

def solve_testcase():
    s = input().split('0')
    res = ''
    for s0 in s:
        if not s0: continue
        c = s0[0]
        v = keys[c]
        res += v[(len(s0)-1) % len(v)]

    print(res)

def main():
    n = int(input())
    for _ in range(n): solve_testcase()

main()

Submission status: Accepted

Solution code:

N=int(input())

button=[[],
        ['.',',','!','?'," "],
        ['a','b','c'],
        ['d','e','f'],
        ['g','h','i'],
        ['j','k','l'],
        ['m','n','o'],
        ['p','q','r','s'],
        ['t','u','v'],
        ['w','x','y','z'],
        ]


for i in range(N):
    S=str(input())
    S=[i + " " for i in S]
    moji=""
    for i in S:
        moji+=i
    S=list(map(int,moji.split()))
    #print(S)
    forward=[0,0]
    for i in S:
        if forward[0]==i and forward[0]!=0:
            forward[1]+=1
            if forward[1]>len(button[i])-1:
                forward[1]=0

        if i==0 and forward!=[0,0]:
            print(button[forward[0]][forward[1]],end="")
            forward[1]=0
        forward[0]=i
        #print(forward)
    print("\n",end="")

Submission status: Accepted

Solution code:
n = int(input())
abc = [".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]
for i in range(n):
  s = input()
  ans = ""
  cur = -1
  num = -1
  for e in s:
    e = int(e)
    if cur ==-1 and e==0:
      continue
    elif e==0:
      t = len(abc[cur-1])
      ans += abc[cur-1][num%t]
      num = -1
      cur = -1
    else:
      cur = e
      num += 1
  print(ans)

Submission status: Accepted

Solution code:
codes = [
    [],
    list('.,!? '),
    list('abc'),
    list('def'),
    list('ghi'),
    list('jkl'),
    list('mno'),
    list('pqrs'),
    list('tuv'),
    list('wxyz'),
]

n = int(input())
for _ in range(n):
    s = input()
    i = None
    cnt = 0
    ans = ''
    for si in list(s):
        sii = int(si)
        if sii == 0:
            if i is not None:
                ans += codes[i][cnt % len(codes[i])]
            i = None
        else:
            if i != sii:
                i = sii
                cnt = 0
            else:
                cnt += 1
    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
k=[[],[".",",","!","?"," "],["a","b","c"],["d","e","f"],["g","h","i"],["j","k","l"],["m","n","o"],["p","q","r","s"],["t","u","v"],["w","x","y","z"]]
for i in range(n):
  b=input()
  #print(b)
  S=[]
  count=0
  for i in range(len(b)):
    if b[i]=="0":
      if count==0:
        pass
      else:
        if b[i-1]=="1":
          co=count%5-1
          S.append(k[1][co])
          count=0
        elif b[i-1]=="2":
          co=count%3-1
          S.append(k[2][co])
          count=0
        elif b[i-1]=="3":
          co=count%3-1
          S.append(k[3][co])
          count=0
        elif b[i-1]=="4":
          co=count%3-1
          S.append(k[4][co])
          count=0
        elif b[i-1]=="5":
          co=count%3-1
          S.append(k[5][co])
          count=0
        if b[i-1]=="6":
          co=count%3-1
          S.append(k[6][co])
          count=0
        if b[i-1]=="7":
          co=count%4-1
          S.append(k[7][co])
          count=0
        if b[i-1]=="8":
          co=count%3-1
          S.append(k[8][co])
          count=0
        if b[i-1]=="9":
          co=count%4-1
          S.append(k[9][co])
          count=0
    else:
      count+=1
    
  for i in range(len(S)):
    print(S[i],end="")
  print("")

Submission status: Accepted

Solution code:
def set(mess) :
  Mess = list(mess.split("0"))
  Ml = len(Mess)
  for i in range(Ml) :
    if("" in Mess) :
      Mess.remove("")
      # Mess 内の1番インデックスの小さい""を削除
    else :
      break
  ML = len(Mess)
  change(Mess, ML)

def change(Mess, ML) :
  one = [".", ",", "!", "?", " "]
  alpha = [chr(i) for i in range(97, 97 + 26)]

  Num = list()
  Cnt = list()
  for i in range(ML) :
    a = list(Mess[i])
    Num.append(a[0])
    Cnt.append(len(a))

  ans = list()
  for i in range(ML) :
    if(Num[i] == "1") :
      ans.append(one[Cnt[i] % 5 - 1])
    elif(Num[i] == "7") :
      ans.append(alpha[(Cnt[i]-1)% 4 + 15])
    elif(Num[i] == "8") :
      ans.append(alpha[(Cnt[i]-1)% 3 + 19])
    elif(Num[i] == "9") :
      ans.append(alpha[(Cnt[i]-1)% 4 + 22])
    else :
      x = 3 * (int(Num[i]) - 2)
      ans.append(alpha[(Cnt[i]-1) % 3 + x])

  for j in range(len(ans)) :
    if(j == len(ans) - 1) :
      print(ans[j])
    else :
      print(ans[j], end = "")

N = int(input())
for i in range(N) :
  mess = input()

  set(mess)

Submission status: Accepted

Solution code:
# Keitai Message

ans = []

words = [0, [".", ",", "!", "?", " "]
        , ["a", "b", "c"]
        , ["d", "e", "f"]
        , ["g", "h", "i"]
        , ["j", "k", "l"]
        , ["m", "n", "o"]
        , ["p", "q", "r", "s"]
        , ["t", "u", "v"]
        , ["w", "x", "y", "z"]
        ]

n = int(input())
for j in range(n):
    a = list(input())
    tips = []
    cnt = 1
    ansT = ""
    for i in range(1, len(a)):
        if a[i] == a[i-1]:
            cnt += 1
        else:
            tips.append([int(a[i-1]), cnt])
            cnt = 1
    tips.append([int(a[-1]), cnt])

    for i in tips:
        if i[0] == 0:
            pass
        else:
            ansT += words[i[0]][i[1] % len(words[i[0]]) - 1]

    ans.append(ansT)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
alpha = [[], list(".,!? "), list("abc"), list("def"), list("ghi"),
         list("jkl"), list("mno"), list("pqrs"), list("tuv"), list("wxyz")]

n = int(input())
for _ in range(n):
    button = list(input())
    button = [int(b) for b in button]

    while 1:
        if button[0] == 0:
            button.pop(0)
        else:
            break

    ans = ""
    cnt = 0
    for i, b in enumerate(button):
        if b == 0 and button[i-1] != 0:
            ans += alpha[button[i-1]][(cnt-1) % len(alpha[button[i-1]])]
            cnt = 0
        elif b == 0:
            pass
        else:
            cnt += 1

    print(ans)

Submission status: Accepted

Solution code:
d=[1,'.,!? ','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz'];[print(''.join(d[int(s[0])][len(s)%len(d[int(s[0])])-1]if s!=''else''for s in t))for t in[input().split('0')for _ in[0]*int(input())]]

Submission status: Accepted

Solution code:
dic={
    '1':'.,!? ',
    '2':'abc',
    '3':'def',
    '4':'ghi',
    '5':'jkl',
    '6':'mno',
    '7':'pqrs',
    '8':'tuv',
    '9':'wxyz'
}

for i in range(int(input())):
    s=input().split('0')
    for c in s:
        if c=='':
            continue
        print(dic[c[0]][(len(c)-1)%len(dic[c[0]])],end='')
    print()

Submission status: Accepted

Solution code:
d = {
    "1": ".,!? ",
    "2": "abc",
    "3": "def",
    "4": "ghi",
    "5": "jkl",
    "6": "mno",
    "7": "pqrs",
    "8": "tuv",
    "9": "wxyz",
    "0": None
}

def solve(input):
    ret = ""
    state = "0"
    cnt = 0
    for c in input:
        if state != c and state is not "0":
            ret += d[state][(cnt-1) % len(d[state])]
            cnt = 0
        elif c is "0":
            cnt = 0
        else:
            cnt += 1
        state = c
    return ret

N = int(raw_input())
for _ in range(N):
    input = raw_input()
    print solve(input)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void){
  int n, i, cnt;
  string str, ans;
  char init;
  vector<string> mp{"", ".,!? ","abc","def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  cin >> n;
  while(n--){
    cin >> str;
    ans = "";
    i = 0;
    while(i < str.length()){
      while(str[i] == '0'){
        i++;
      }
      if(i >= str.length()){
        break;
      }
      init = str[i];
      cnt = 0;
      while(i < str.length() and str[i] == init){
        i++;
        cnt++;
      }
      ans += mp[init - '0'][(cnt - 1) % mp[init - '0'].length()];
    }
    cout << ans << endl;
  }
  return 0;
}

Submission status: Runtime Error

Solution code:
N = int(input())
d = []
d.append([])
d.append([".",",","!","?"])
d.append(["a","b","c"])
d.append(["d","e","f"])
d.append(["g","h","i"])
d.append(["j","k","l"])
d.append(["m","n","o"])
d.append(["p","q","r","s"])
d.append(["t","u","v"])
d.append(["w","x","y","z"])
for _ in range(N):
    nn = input()
    output = ""
    b = 0
    c = 0
    for n in nn:
        n = int(n)
        if n == 0:
            output += d[b][c]
            c = 0
        b = n

Submission status: Runtime Error

Solution code:
N = int(input())
d = []
d.append([])
d.append([".",",","!","?"])
d.append(["a","b","c"])
d.append(["d","e","f"])
d.append(["g","h","i"])
d.append(["j","k","l"])
d.append(["m","n","o"])
d.append(["p","q","r","s"])
d.append(["t","u","v"])
d.append(["w","x","y","z"])
for _ in range(N):
    nn = input()
    output = ""
    b = 0
    c = 0
    for n in nn:
        n = int(n)
        if n == 0:
            output += d[b][c]
            c = 0
        c += 1
    print(output)

Submission status: Runtime Error

Solution code:
d = {1:{1:'.',2:',',3:'!',4:'?',5:' '},
     2:{1:'a',2:'b',3:'c'},
     3:{1:'d',2:'e',3:'f'},
     4:{1:'g',2:'h',3:'i'},
     5:{1:'j',2:'k',3:'l'},
     6:{1:'m',2:'n',3:'o'},
     7:{1:'p',2:'q',3:'r',4:'s'},
     8:{1:'t',2:'u',3:'v'},
     9:{1:'w',2:'x',3:'y',4:'z'}
}
n = int(raw_input())
for i in range(n):
    mes = raw_input()
    mes = mes.split("0")
    mes=filter(lambda x:len(x)>0,mes)
    #print mes
    l=[]
    for e in mes:
        l.append([e[0], len(e)])
    res=""
    for e in l:
        i=int(e[0])
        if(i==1):
            if e[1]>5:x=e[1]%5
            else:x=e[1]
        elif(i==7 or i==9):
            if e[1]>4:x=e[1]%4
            else:x=e[1]
        else:
            if e[1]>3:x=e[1]%3
            else:x=e[1]
        res=res+d[i][x]

    print res

Submission status: Runtime Error

Solution code:
d = {1:{1:'.',2:',',3:'!',4:'?',5:' '},
     2:{1:'a',2:'b',3:'c'},
     3:{1:'d',2:'e',3:'f'},
     4:{1:'g',2:'h',3:'i'},
     5:{1:'j',2:'k',3:'l'},
     6:{1:'m',2:'n',3:'o'},
     7:{1:'p',2:'q',3:'r',4:'s'},
     8:{1:'t',2:'u',3:'v'},
     9:{1:'w',2:'x',3:'y',4:'z'}
}
n = int(raw_input())
for i in range(n):
    mes = raw_input()
    mes = mes.split("0")
    mes=filter(lambda x:len(x)>0,mes)
    l=[]
    for e in mes:
        l.append([e[0], len(e)])
    res=""
    for e in l:
        i=int(e[0])
        if(i==1):
            if e[1]>5:x=e[1]%5
            else:x=e[1]
        elif(i==7 or i==9):
            if e[1]>4:x=e[1]%4
            else:x=e[1]
        else:
            if e[1]>3:x=e[1]%3
            else:x=e[1]
            res=res+d[i][x]

    print res

Submission status: Runtime Error

Solution code:
#coding: utf-8

import sys

def keitai(n1,n2):
    li1 = ['.', ',', '!', '?'] 
    li2 = ['a','b','c']
    li3 = ['d','e','f']
    li4 = ['g','h','i']
    li5 = ['j','k','l']
    li6 = ['m','n','o']
    li7 = ['p','q','r','s']
    li8 = ['t','u','v']
    li9 = ['w','x','y','z']
    li = [li1,li2,li3,li4,li5,li6,li7,li8,li9]
    lis = li[n1 - 1]
    n2 = n2 % len(li)
    a = lis[n2 - 1]
    return a

for line in sys.stdin:
    a = str(line)
    num = 0
    for i in len(a):
        if int(a[i]) == 0:
            print keitai(b,num),
        else:
            num = num + 1
            b = int(a[i])
    print ''

Submission status: Runtime Error

Solution code:
#coding: utf-8

import sys

def keitai(n1,n2):
    li1 = ['.', ',', '!', '?'] 
    li2 = ['a','b','c']
    li3 = ['d','e','f']
    li4 = ['g','h','i']
    li5 = ['j','k','l']
    li6 = ['m','n','o']
    li7 = ['p','q','r','s']
    li8 = ['t','u','v']
    li9 = ['w','x','y','z']
    li = [li1,li2,li3,li4,li5,li6,li7,li8,li9]
    lis = li[n1 - 1]
    n2 = n2 % len(li)
    a = lis[n2 - 1]
    return a

for line in sys.stdin:
    a = str(line)
    num = 0
    for i in len(a):
        if int(a[i]) == 0:
            if i = len(a) - 1:
                print keitai(b,num)
            else:
                print keitai(b,num),
        else:
            num = num + 1
            b = int(a[i])

Submission status: Runtime Error

Solution code:
#coding: utf-8

import sys

def keitai(n1,n2):
    li1 = ['.', ',', '!', '?',' '] 
    li2 = ['a','b','c']
    li3 = ['d','e','f']
    li4 = ['g','h','i']
    li5 = ['j','k','l']
    li6 = ['m','n','o']
    li7 = ['p','q','r','s']
    li8 = ['t','u','v']
    li9 = ['w','x','y','z']
    li = [li1,li2,li3,li4,li5,li6,li7,li8,li9]
    lis = li[n1 - 1]
    n2 = n2 % len(lis)
    a = lis[n2 - 1]
    return a

for line in sys.stdin:
    a = str(line)
    num = 0
    string = ''
    for i in range(len(a)):
        if int(a[i]) == 0:
            string = string + keitai(b,num)
            num = 0
        else:
            num = num + 1
            b = int(a[i])
    print string

Submission status: Runtime Error

Solution code:
#coding: utf-8

n = raw_input()

def keitai(n1,n2):
    li1 = ['.', ',', '!', '?',' '] 
    li2 = ['a','b','c']
    li3 = ['d','e','f']
    li4 = ['g','h','i']
    li5 = ['j','k','l']
    li6 = ['m','n','o']
    li7 = ['p','q','r','s']
    li8 = ['t','u','v']
    li9 = ['w','x','y','z']
    li = [li1,li2,li3,li4,li5,li6,li7,li8,li9]
    lis = li[n1 - 1]
    n2 = n2 % len(lis)
    a = lis[n2 - 1]
    return a

for k in range(n):
    a = str(raw_input())
    num = 0
    string = ''
    for i in range(len(a)):
        if int(a[i]) == 0:
            string = string + keitai(b,num)
            num = 0
        else:
            num = num + 1
            b = int(a[i])
    print string

Submission status: Runtime Error

Solution code:
import re

di = {1:".,!? ",2:"abc",3:"def",4:"ghi"
         ,5:"jkl",6:"mno",7:"pqrs",8:"tuv",9:"wxyz"}
while True:
    str = ""
    line = raw_input()
    if line.endswith("0") is False:
        break
    list = re.split("0+",line)
    for line in list:
        if line is not '':
            index = (len(line)-1)%len(di[int(line[:1])])
            first_num = int(line[:1])
            str += di[first_num][index]
    print str

Submission status: Runtime Error

Solution code:
import re

di = {1:".,!? ",2:"abc",3:"def",4:"ghi"
         ,5:"jkl",6:"mno",7:"pqrs",8:"tuv",9:"wxyz"}
while True:
    str = ""
    line = raw_input()
    if line.endswith("0") is False:
        break
    list = re.split("0+",line)
    for line in list:
        if line is not '':
            str += di[int(line[:1])][(len(line)-1)%len(di[int(line[:1])])]
    print str

Submission status: Runtime Error

Solution code:
import re

di = {1:".,!? ",2:"abc",3:"def",4:"ghi"
         ,5:"jkl",6:"mno",7:"pqrs",8:"tuv",9:"wxyz"}
while True:
    str = ""
    line = raw_input()
    if line.endswith("0") is False:
        break
    list = re.split("0+",line)
    for line in list:
        if line is not '' and len(set(line)) < 2:
            first_num = int(line[:1])
            str += di[first_num][(len(line)-1)%len(di[int(line[:1])])]
    if str is not "":
        print str

Submission status: Runtime Error

Solution code:
import sys
di = {1:".,!? ",2 :"abc",3:"def",4:"ghi",5:"jkl",6:"mno",7:"pqrs",8:"tuv",9:"wxyz"}
while True:
    a = raw_input()
    count = 0
    le = 999
    fl = False
    for letter in a:
        if(letter == "0"):
            if(le == 999):
                pass
            else:
                sys.stdout.write(di[le][(count-1)%len(di[le])])
                count = 0
                le = 999
                fl = True
        else:
            le = int(letter)
            count += 1
    if(fl):
        print ""

Submission status: Runtime Error

Solution code:
moji_lis = [[".",",","!","?"," "],["a","b","c"],["d","e","f"],["g","h","i"],["j","k","l"],["m","n","o"],["p","q","r","s"],["t","u","v"],["w","x","y","z"]]
n = int(input())
for i in range(n):
    N_lis = list(input())
    N_lis = list(map(int,N_lis))
    
    a_0 = N_lis[0]
    n_num = 1
    moji = ""
    for j in range(1,len(N_lis)):

        a_1 = N_lis[j]
        
        if a_0 == a_1:
            n_num += 1
        else:
            if a_0 == 1:
                moji += moji_lis[0][(n_num - 1) % 5]
                
            elif a_0 == 6 or a_0 == 8:
                moji += moji_lis[a_0 - 1][(n_num - 1) % 4]
                
            elif a_0 != 0:
                moji += moji_lis[a_0 - 1][(n_num - 1) % 3]
                
        a_0 = a_1
        if a_1 == 0:
            n_num = 1
    print(moji)