eolymp
bolt
Try our new interface for solving problems
Problems

Simple Stack

Simple Stack

Design and implement the data structure "\textbf{stack}". Write the program to simulate the stack operations, implement all methods mentioned below. The program reads the sequence of commands and executes the corresponding operation. After processing each command the program must print one line of output. The possible commands are: \begin{itemize} \item \textbf{push n} --- Add to the stack the number $n$ (value $n$ is given after the command). Print \textbf{ok}. \item \textbf{pop} --- Remove the last element from the stack. Print the value of this element. \item \textbf{back} --- Print the value of the last element, not removing it from the stack. \item \textbf{size} --- Print the number of elements in the stack. \item \textbf{clear} --- Clear the stack and print \textbf{ok}. \item \textbf{exit} --- Print \textbf{bye} and terminate. \end{itemize} \includegraphics{https://static.e-olymp.com/content/f8/f890bb5aefd77b42f6c04a20c1db67910367e0c3.gif} It is guaranteed that the set of input commands satisfies the following requirements: the maximum number of elements in the stack at any time does not exceed $100$, all commands \textbf{pop} and \textbf{back} are correct, that is, when executed the stack contains at least one element. \InputFile Each line contains a single command. \OutputFile For each command print on a separate line the corresponding result.
Time limit 2 seconds
Memory limit 128 MiB
Input example #1
push 2
push 3
push 5
back
size
pop
size 
push 7 
pop 
clear 
size 
exit
Output example #1
ok
ok
ok
5
3
5
2
ok
7
ok
0
bye