fork download
  1. import sys
  2. input = sys.stdin.readline
  3. print = sys.stdout.write
  4.  
  5. def radix_sort(nums):
  6. maxNum = max(nums)
  7. maxLen = len(str(maxNum))
  8.  
  9. for i in range(maxLen):
  10. radix = [[] for _ in range(10)]
  11.  
  12. for num in nums:
  13. digit = (num // (10 ** i)) % 10
  14. radix[digit].append(num)
  15.  
  16. nums = [num for bucket in radix for num in bucket]
  17.  
  18. return nums
  19.  
  20.  
  21. N = int(input())
  22.  
  23. nums = []
  24. positive = []
  25. negative = []
  26. for i in range(N):
  27. a = int(input())
  28. if a < 0:
  29. negative.append(a)
  30. else:
  31. positive.append(a)
  32.  
  33.  
  34. positive = radix_sort(positive)
  35. if negative:
  36. negative = [(-1 * num) for num in negative]
  37. negative = radix_sort(negative)
  38. negative = [(-1 * num) for num in negative]
  39. negative.reverse()
  40. nums = negative + positive
  41. else:
  42. nums = positive
  43.  
  44.  
  45. for n in nums:
  46. print(str(n) + '\n')
  47.  
Runtime error #stdin #stdout #stderr 0.16s 25408KB
stdin
1
-1
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 34, in <module>
  File "./prog.py", line 6, in radix_sort
ValueError: max() arg is an empty sequence