fork download
  1. import sys
  2.  
  3. digits ="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  4.  
  5. def base2base(number,rBase,sBase):
  6. '''
  7. # Implementation of Any base to Decimal, but int() is faster
  8. dec = 0
  9. for n in number:
  10. dec = digits.index(n,0,rBase) + dec * rBase
  11. '''
  12. dec = int(number,rBase)
  13. result = []
  14. while(dec != 0):
  15. dec,mod = divmod(dec, sBase)
  16. result.insert(0,digits[mod])
  17. for i in result:
  18. sys.stdout.write( "%s" % (i))
  19. print
  20.  
  21.  
  22. instances = int(raw_input())
  23. for v in range(0,instances):
  24. data = raw_input().split(" ")
  25. number = data[0]
  26. rBase = int(data[1])
  27. sBase = int(data[2])
  28. if(number != '0'):
  29. base2base(number,rBase,sBase)
  30. #print dec2Base(sBase,int(number,rBase))
  31. else:
  32. print 0
Success #stdin #stdout 0.01s 7740KB
stdin
4
56378 10 2
AB98BC 15 10
ABCDEF123456 36 2
1000100101010 2 10
stdout
1101110000111010
8182977
1001011010111011111010000110001101100010101101000110110111010
4394