Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- encoding:utf-8 -*-
- import string
- """
- versão para o spoj-br
- """
- class Encotel(object):
- def get_number(self, x):
- "Retorna os números equivalentes aos caracteres"
- saida = ''
- mapping = self.get_mapping()
- for s in x:
- if s >= 'A' and s <= 'Z':
- saida += str(mapping.get(s))
- elif s =='0' or s =='1':
- saida += s
- else:
- saida += s
- return saida
- def get_mapping(self):
- "Retorna o mapeamento dos caracteres x números"
- mapping = {}
- for i in string.ascii_uppercase:
- count = string.ascii_uppercase.index(i)
- if count >= 25: #z
- count -= 2
- elif count >= 18:
- count -= 1
- count /= 3
- count += 2
- mapping[i] = count
- return mapping
- while True:
- solver = Encotel()
- try:
- linha = raw_input()
- print solver.get_number(linha)
- except:
- break
Add Comment
Please, Sign In to add comment