Problem list
Log in
#r03358 · Online Judge > GoldOJ

Stack Commands

Silver IV 2.0 s 1024 MB

Implement an integer stack and process $n$ commands: push x pushes $x$; pop removes and prints the top (or $-1$ if empty); top prints the top (or $-1$ if empty); size prints the number of elements; empty prints $1$ if empty else $0$.

Input

First line $n$ ($1 \le n \le 100000$); then $n$ command lines. At least one command produces output.

Output

Print the result of each output-producing command, one per line.

Example 1

Input
5
push 1
top
pop
pop
empty
Output
1
1
-1
1
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code