spheret 3081 look and say

Anuncio
# spoj tutorial 3081 LOOKSAY Look and Say
# python 2.7
def lookSay(s):
# proximo numero descrito verbalmente
f = 1 # frecuencia
c = s[0] # caracter
sg = '' # siguiente
for i in range(1, len(s), 1):
if s[i] == c:
f += 1
else:
sg += str(f)
sg += c
f=1
c = s[i]
sg += str(f)
sg += c
return sg
# 'main'
t = input() # casos
for i in range(t):
n = raw_input()
print lookSay(n)
# sph, ecabrera, marzo 2016
Descargar