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: Wrong Answer

Solution code:
def solve(mm, cmd):
	bf = cmd[0]
	c = 0
	ans = ""
	for s in cmd[1::]:
			if bf == s:
				c += 1
			else:
				if s == '0':
					ans += mm[bf][c%len(mm[bf])]
				c = 0
				bf = s
	return ans

def main():
	N = int(input())
	cc = [
		[".",",","!","?"," "],
		["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"]]
	mm = dict(zip(
		[str(i) for i in range(1,10)],
		cc
	))
	print(mm)
	for _ in range(N):
		cmd = input()
		print(solve(mm,cmd))

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        t = {
            0: [],
            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 i in range(n):
            ans = ''
            prev = 0
            count = 0
            for c in raw_input():
                if c == '0':
                    if prev == 0:
                        continue
                    ans += t[prev][count-1]
                    prev = 0
                    count = 0
                else:
                    prev = int(c)
                    count += 1
                    count %= len(t[prev])
                    print prev, count
            print ans
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

def atoi(c):
    return ord(c) - ord('0')

table = [(), #dummy
        ('.',',','!','?'),\
        ('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):
    digits = list(input())
    s = ""
    c = ''
    m = 0
    for d in digits:
        if d == '0':
            s += c
            c = ''
            m = 0
        else:
            c = table[atoi(d)][m]
            m = (m + 1) % len(table[atoi(d)])
    print(s)

Submission status: Wrong Answer

Solution code:
#coding: utf-8

n = int(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: Wrong Answer

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])])]
        else:
            break;
    if str is "":
        break
    else:
        print str

Submission status: Wrong Answer

Solution code:
import re

di = {1:".,!? ",2:"abc",3:"def",4:"ghi"
         ,5:"jkl",6:"mno",7:"pqrs",8:"tuv",9:"wxyz"}
str = ""
line = raw_input()
if line.endswith("0") is True:
    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: Wrong Answer

Solution code:
import re

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

Submission status: Wrong Answer

Solution code:
import sys
di = {1:".,!? ",2 :"abc",3:"def",4:"ghi",5:"jkl",6:"mno",7:"pqrs",8:"tuv",9:"wxyz"}
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: Wrong Answer

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 = int(input())
m = [input() for i in range(n)]
for mm in m:
    l = [x for x in mm.split('0') if not x == '']
    for x in l:
        print(d[x[0]][len(x)%len(d[x[0]]) - 1])
    print()

Submission status: Wrong Answer

Solution code:
def moji(x,ans):
    if ans == 0:
        return
    if x == 1:
        if(ans%4==1):
            str = '.'
        elif(ans%4==2):
            str =','
        elif(ans%4==3):
            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: Wrong Answer

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: Wrong Answer

Solution code:
strMap=[[],
        ['.',',','!','?',' '],
        ['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']
        ]
ans=[]
while True:
    try:
        ent=raw_input()
    except EOFError:
        break
    curAns=''
    entLen=len(ent)
    ent=list(ent)
    prvNum=0
    times=0
    for i in xrange(entLen):
        cmd=int(ent.pop(0))
        if cmd==0 and not prvNum == 0:
            curAns+=strMap[prvNum][(times % len(strMap[prvNum]))]
            prvNum=0
            times=0
        else:
            if cmd != prvNum:
                times=0
                prvNum=cmd
            else:
                times+=1
    ans.append(curAns)

for i in ans:
    print i

Submission status: Wrong Answer

Solution code:
strMap=[[],
        ['.',',','!','?',' '],
        ['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']
        ]
ans=[]
while True:
    try:
        ent=raw_input()
    except EOFError:
        break
    curAns=''
    entLen=len(ent)
    ent=list(ent)
    prvNum=0
    times=0
    for i in xrange(entLen):
        cmd=int(ent.pop(0))
        if cmd==0 and not prvNum == 0:
            curAns+=strMap[prvNum][(times % len(strMap[prvNum]))]
            prvNum=0
            times=0
        else:
            if cmd != prvNum:
                times=0
                prvNum=cmd
            else:
                times+=1
    ans.append(curAns)

for i in ans:
    if i != '':
        print i

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

a = ['_','.,!? ','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
for s in stdin:
	b = [[i for i in j] for i,j in groupby(s.strip())]
	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:
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"],
]

N = int(input())
for _ in range(N):
    S = ""
    count = 0
    l = list(input())
    for i in range(0, len(l)):
        if l[i] == "0":
            S += button[int(l[i - 1])][count-1]
            count = 0
        else:
            # print(l[i])
            count = (count + 1) % len(button[int(l[i])])
    print(S)

Submission status: Accepted

Solution code:
def solve(mm, cmd):
	bf = cmd[0]
	c = 0
	ans = ""
	for s in cmd[1::]:
			if bf == s:
				c += 1
			else:
				if s == '0':
					ans += mm[bf][c%len(mm[bf])]
				c = 0
				bf = s
	return ans

def main():
	N = int(input())
	cc = [
		[".",",","!","?"," "],
		["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"]]
	mm = dict(zip(
		[str(i) for i in range(1,10)],
		cc
	))
	for _ in range(N):
		cmd = input()
		print(solve(mm,cmd))

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
w = [[''],['.',',','!','?',' '], ['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 _ in range(n):
    buff = ''
    s = input()
    push = 0
    times = 0
    for c in s:
        if int(c) == 0:
            buff += w[push][times%len(w[push])]
        if int(c) == push:
            times += 1
        else:
            push = int(c)
            times = 0
    print(buff)

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        t = {
            0: [],
            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 i in range(n):
            ans = ''
            prev = 0
            count = 0
            for c in raw_input():
                if c == '0':
                    if prev == 0:
                        continue
                    ans += t[prev][count-1]
                    prev = 0
                    count = 0
                else:
                    prev = int(c)
                    count += 1
                    count %= len(t[prev])
                    # print prev, count
            print ans
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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']]

n = int(input())
for i in range(n):
    inputStr = list(map(int,list(input())))
    count = 0
    for j in range(len(inputStr)):
        if inputStr[j] != 0:
            count += 1
        if inputStr[j] == 0 and j -1 >= 0 and  inputStr[j-1] != 0:
            print(button[inputStr[j-1]][(count-1)%len(button[inputStr[j-1]])],end='')
            count = 0
    print()

Submission status: Accepted

Solution code:
class Button :
	def __init__(self):
		self.key_dict = {
					("","1"): ".", (".","1"):",", (",","1"):"!",
					("!","1"):"?", ("?","1"):" ", (" ","1"):".",
					("","2"): "a", ("a","2"):"b", ("b","2"):"c", ("c","2"):"a",
					("","3"): "d", ("d","3"): "e", ("e","3"): "f", ("f","3"): "d",
					("","4"): "g", ("g","4"): "h", ("h","4"): "i", ("i","4"): "g",
					("","5"): "j", ("j","5"): "k", ("k","5"): "l", ("l","5"): "j",
					("","6"): "m", ("m","6"): "n", ("n","6"): "o", ("o","6"): "m",	
					("","7"): "p", ("p","7"): "q", ("q","7"): "r", ("r","7"): "s", ("s","7"): "p",
					("","8"): "t", ("t","8"): "u", ("u","8"): "v", ("v","8"): "t",
					("","9"): "w", ("w","9"): "x", ("x","9"): "y", ("y","9"): "z", ("z","9"): "w"
						}
		self.s = ""
	def push(self, key):
		if key == "0":
			char = self.s
			self.s = ""
			return char
		else :
			self.s = self.key_dict[(self.s, key)]

n = int(raw_input())
button = Button()
for i in range(n):
	message = ""
	key_string = raw_input()
	for key in key_string:
		if key == "0":
			message += button.push(key)
		else :
			button.push(key)
	print message

Submission status: Accepted

Solution code:
#! /usr/bin/python
# -*- coding: utf-8 -*-

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"]]

n = int(raw_input())
for i in range(n):
    m = raw_input()
    ans = ""
    pre = '0'
    cnt = 0
    for j in range(len(m)):
        if m[j] == '0':
            if cnt == 0:
                pass
            elif pre == '1':
                ans += (table[1][(cnt-1)%5])
            elif pre == '7' or pre == '9':
                ans += (table[int(pre)][(cnt-1)%4])
            else:
                ans += (table[int(pre)][(cnt-1)%3])
            cnt = 0
        else:
            pre = m[j]
            cnt += 1
    print ans

Submission status: Accepted

Solution code:
#!/usr/bin/python3

def atoi(c):
    return ord(c) - ord('0')

table = [(), #dummy
        ('.',',','!','?',' '),\
        ('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):
    digits = list(input())
    s = ""
    c = ''
    m = 0
    for d in digits:
        if d == '0':
            s += c
            c = ''
            m = 0
        else:
            c = table[atoi(d)][m]
            m = (m + 1) % len(table[atoi(d)])
    print(s)

Submission status: Accepted

Solution code:
import itertools

table = {	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()
	r = ''
	for k, g in itertools.groupby(s):
		if k == '0':
			continue
		k = int(k)
		i = (len(list(g)) - 1) % len(table[k])
		r += table[k][i]
	print(r)

Submission status: Accepted

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==0:x=5
            else:x=e[1]%5
        elif(i==7 or i==9):
            if e[1]%4==0:x=4
            else:x=e[1]%4
        else:
            if e[1]%3==0:x=3
            else:x=e[1]%3
        res=res+d[i][x]

    print res

Submission status: Accepted

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

n = int(raw_input())

for _ in range(n):
    ans = ""
    inputs = map(str, raw_input().split('0'))

    for i in inputs:
        if len(i) > 0:
            k = i[0]
            ans += ref[k][(len(i) - 1) % len(ref[k])]
    print ans

Submission status: Accepted

Solution code:
dats=[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']]
for p in range(input()):
    a=raw_input().split('0')
    b=""
    for i in range(len(a)):
        if a[i]!="":
            c=a[i]
            b=b+dats[int(c[0])][len(c)%len(dats[int(c[0])])-1]
    print(b)

Submission status: Accepted

Solution code:
chars = (None, '.,!? ', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz')
n = int(input())

while n:
    n -= 1
    s = input()
    number, counter = 0, 0
    for c in s:
        if c == '0':
            if number:
                charset = chars[number]
                print(charset[(counter - 1) % len(charset)], end='')
                number, counter = 0, 0
        elif counter:
            counter += 1
        else:
            number = int(c)
            counter = 1
    print()

Submission status: Accepted

Solution code:
btn = [None, ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]
for t in range(input()):
    state = 0
    cnt = -1
    ans = ""
    for c in map(int, raw_input()):
        if c:
            cnt += 1
            state = c
        else:
            if state:
                tgt = btn[state]
                ans += tgt[cnt % len(tgt)]
            state = 0
            cnt = -1
    print ans

Submission status: Accepted

Solution code:
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"]]

n = int(raw_input())
for _ in xrange(n):
  s = raw_input()
  inbut = 0
  count = 0
  output = ""
  for i in xrange(len(s)):
    if s[i] == "0":
      if inbut == 0: continue
      output += button[inbut-1][(count-1) % len(button[inbut-1])]
      inbut = 0
      count = 0
    else:
      inbut = int(s[i])
      count += 1
  print output

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8
 
n = int(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:
            if num != 0:
                string = string + keitai(b,num)
                num = 0
            else:
                pass
        else:
            num = num + 1
            b = int(a[i])
    print string

Submission status: Accepted

Solution code:
s = [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']]
for _ in range(int(input())):
    l = list(filter(lambda x: x!='', input().split('0')))
    r = ''
    for d in l:
        i,j = int(d[0]),len(d)-1
        r += s[i][j%len(s[i])]
    print(r)

Submission status: Accepted

Solution code:
a=[['.',',','!','?',' '],['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 _ in range(int(input())):
    b=list(filter(lambda x: x!='',input().split('0')))
    for c in b:
        d=int(c[0])-1
        print(a[d][(len(c)-1)%len(a[d])],end='')
    print()

Submission status: Accepted

Solution code:
char = ["",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"]
n = int(input())

for _ in range(n):
    s = input()
    ans = ""
    flag = True
    prev = 0
    cnt = 0
    for i in s:
        if i != '0':
            prev = int(i)
            cnt += 1
        elif cnt != 0:
            ans += char[prev][(cnt - 1) % len(char[prev])]
            cnt = 0
    print(ans)

Submission status: Accepted

Solution code:
lst = [('.',',','!','?',' '),
       ('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())):
    ans = ""
    x = raw_input().split("0")
    while '' in x: x.remove('')
    for j in range(len(x)):
        ans += lst[int(x[j])%10-1][(len(x[j])-1)%len(lst[int(x[j])%10-1])]
    print ans

Submission status: Accepted

Solution code:
import sys
di = {1:".,!? ",2 :"abc",3:"def",4:"ghi",5:"jkl",6:"mno",7:"pqrs",8:"tuv",9:"wxyz"}
b = input()

for j in range(b):
    a = raw_input()
    count = 0
    le = 999
    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
        else:
            le = int(letter)
            count += 1
    print ""

Submission status: Accepted

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 == 7 or a_0 == 9:
        
                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)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    moji =[[],[' ','.',',','!','?'],['c','a','b'],['f','d','e'],['i','g','h'],['l','j','k'],['o','m','n'],['s','p','q','r'],['v','t','u'],['z','w','x','y']]
    for _ in range(n):
        line = list(input().strip().replace('0',' ').split())
        ans = []
        for i in line:
            m=int(i[0])
            ans.append(moji[m][len(i)%len(moji[m])])
        print(''.join(ans))

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 = int(input())
m = [input() for _ in range(n)]
for line in m:
    ans = []
    for cs in line.split("0"):
        if cs == "":
            continue
        index = len(cs) % len(d[cs[0]]) - 1
        ans.append(d[cs[0]][index])
    print("".join(ans))

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 = int(input())
m = [input() for _ in range(n)]
ans = [[d[cs[0]][len(cs) % len(d[cs[0]]) - 1] for cs in line.split("0") if cs != ""] for line in m]
for a in ans:
    print(*a, sep="")

Submission status: Accepted

Solution code:
dic = [None, '.,!? ','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']

N = int(input())
for i in range(N):
    S = input()
    ans = ''
    btn = n = -1
    for c in S:
        if c == '0':
            if btn > 0:
                ans += dic[int(btn)][n % len(dic[int(btn)])]
                btn = n = -1
        else:
            btn = int(c)
            n += 1
    print(ans)

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 = int(input())
m = [input() for i in range(n)]
for mm in m:
    l = [x for x in mm.split('0') if not x == '']
    buf = ''
    for x in l:
        buf += d[x[0]][len(x)%len(d[x[0]]) - 1]
    print(buf)

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 = int(input())
m = [input() for i in range(n)]
for mm in m:
    l = [x for x in mm.split('0') if not x == '']
    for x in l:
        print(d[x[0]][len(x)%len(d[x[0]]) - 1], end='')
    print()

Submission status: Accepted

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

n = int(raw_input())

for _ in range(n):
    msg = raw_input().replace("\r", "")
    ans = ""; j = 0; t = "";

    for i in msg:
        if i == "0":
            ans += t
            j = 0; t = ""
        else:
            t = table[int(i)-1][j]
            j += 1
            j %= len(table[int(i)-1])

    print ans

Submission status: Accepted

Solution code:
table = [".,!? ", "abc", "def", "ghi","jkl",
        "mno", "pqrs", "tuv", "wxyz"]

n = int(raw_input())

for _ in range(n):
    msg = raw_input().replace("\r", "")
    ans = ""; j = 0; t = "";

    for i in msg:
        if i == "0":
            ans += t
            j = 0; t = ""
        else:
            t = table[int(i)-1][j]
            j += 1
            j %= len(table[int(i)-1])

    print ans

Submission status: Accepted

Solution code:
button = [0, ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]

n = int(input())
for i in range(n):
    s = input()

    cnt = 0
    key = "0"

    for c in s:
        if c != "0":
            cnt += 1
            key = c
        else:
            if key == "0":
                cnt = 0
                continue
            else:
                print(button[int(key)][(cnt - 1) % len(button[int(key)])], end = "")
                cnt = 0
                key = "0"

    print()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    n = I()
    a = [S() for _ in range(n)]
    d = {}
    d[1] = '.,!? '
    d[2] = 'abc'
    d[3] = 'def'
    d[4] = 'ghi'
    d[5] = 'jkl'
    d[6] = 'mno'
    d[7] = 'pqrs'
    d[8] = 'tuv'
    d[9] = 'wxyz'
    for s in a:
        r = ''
        i = -1
        c = 0
        for t in s:
            tc = int(t)
            if tc == 0:
                if c > 0:
                    r += d[c][i%len(d[c])]
                i = -1
                c = 0
            else:
                c = tc
                i += 1
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
import sys
K = '.,!? '
A = 'abc'
D = 'def'
G = 'ghi'
J = 'jkl'
M = 'mno'
P = 'pqrs'
T = 'tuv'
W = 'wxyz'
L = ['', K, A, D, G, J, M, P, T, W]
count = int(input())
while count:
	count -= 1
	S = []
	n = input()
	if not '0' in n:
		print('')
		continue
	else:
		n = n.split('0')
		for ns in n:
			if ns == '':
				continue
			i = len(ns) % len(L[int(ns[0])])
			S += [[L[int(ns[0])], i-1]]
		for s in S:
			print(s[0][s[1]], end='')
		print('')
		continue