fork download
  1. import sys
  2.  
  3. MAX = 100
  4.  
  5. class Stack:
  6. # Konstruktor - uruchamia się przy tworzeniu obiektu
  7. def __init__(self):
  8. self.S = [0]*MAX
  9. self.Top = MAX
  10.  
  11. # Dodawanie elementu na stos
  12. def Push(self, e):
  13. self.Top -= 1
  14. self.S[self.Top] = e
  15.  
  16. # Pobieranie elementu ze stosu
  17. def Pop(self):
  18. e = self.S[self.Top]
  19. self.Top += 1
  20. return e
  21.  
  22. # Sprawdzanie, czy stos jest pusty
  23. def Empty(self):
  24. return self.Top == MAX
  25.  
  26.  
  27. # Utworzenie obiektu klasy Stack
  28. s = Stack()
  29.  
  30. # Wczytywanie danych ze standardowego wejścia
  31. for line in sys.stdin:
  32. for x in line.split():
  33. s.Push(x)
  34.  
  35. # Pobieranie elementów, dopóki stos nie jest pusty
  36. while not s.Empty():
  37. print(s.Pop(), " ", end="")
Success #stdin #stdout 0.02s 3784KB
stdin
1
2
3
4
5
stdout
5  4  3  2  1