fork download
  1. """ AUTHOR : PVKCSE
  2. STUDENT AT : ACCET,KKDI
  3. TASK : BASE - SPOJ """
  4.  
  5. import sys
  6.  
  7. symbol_table=[i.upper() for i in "abcdefg"]
  8.  
  9. for line in sys.stdin :
  10. a = line.strip().split()
  11. num = a[0]
  12. base_from = int(a[1])
  13. base_to = int(a[2])
  14. num_10 = 0
  15. prog = 1
  16. inc = 0
  17. for i in reversed(num) :
  18. if ord(i) >=65 :
  19. i = (ord(i) - 65)+10
  20. num_10+=((int(i))*(base_from**inc))
  21. inc +=1
  22. result = ""
  23. if base_to != 10 :
  24. while num_10 > 0 :
  25. temp=(num_10%base_to)
  26. if temp >= 10 :
  27. result+=symbol_table[temp-10]
  28. else :
  29. result+=str(temp)
  30. num_10/=base_to
  31. ans=""
  32. for i in reversed(result) :
  33. ans+=i
  34. result = ans
  35. else :
  36. result+=str(num_10)
  37. if len(result) > 7 :
  38. result = "ERROR"
  39. print str(result).rjust(7)
  40.  
Success #stdin #stdout 0.01s 7900KB
stdin
1111000  2 10
1111000  2 16
2102101  3 10
2102101  3 15
  12312  4  2
     1A 15  2
1234567 10 16
   ABCD 16 15
stdout
    120
     78
   1765
    7CA
  ERROR
  11001
 12D687
   D071