Guest User

Untitled

a guest
Jul 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. # -*- encoding:utf-8 -*-
  2. import string
  3.  
  4. """
  5. versão para o spoj-br
  6. """
  7.  
  8. class Encotel(object):
  9. def get_number(self, x):
  10. "Retorna os números equivalentes aos caracteres"
  11. saida = ''
  12. mapping = self.get_mapping()
  13.  
  14. for s in x:
  15. if s >= 'A' and s <= 'Z':
  16. saida += str(mapping.get(s))
  17. elif s =='0' or s =='1':
  18. saida += s
  19. else:
  20. saida += s
  21.  
  22. return saida
  23.  
  24. def get_mapping(self):
  25. "Retorna o mapeamento dos caracteres x números"
  26. mapping = {}
  27. for i in string.ascii_uppercase:
  28. count = string.ascii_uppercase.index(i)
  29. if count >= 25: #z
  30. count -= 2
  31. elif count >= 18:
  32. count -= 1
  33. count /= 3
  34. count += 2
  35.  
  36. mapping[i] = count
  37. return mapping
  38.  
  39. while True:
  40. solver = Encotel()
  41. try:
  42. linha = raw_input()
  43. print solver.get_number(linha)
  44. except:
  45. break
Add Comment
Please, Sign In to add comment