#include <iostream>
using namespace std;
const short int link_array_size = 30; //количество элементов в одном звене
struct link //звено списка
{
int array [link_array_size]; //массив, элементы которого и являются элементами стека
short int capacity; //свободное место в массиве
link* next; //адресс следующего звена
link () //создание звена
{
capacity = link_array_size;
}
void link_push (int n)
{
capacity--;
array [capacity] = n;
}
int link_pop ()
{
capacity++;
return array[capacity-1];
}
};
struct stack //сам стек
{
link* head; //указатель на первое звено
int s; //количество элементов в стеке
stack (link* h = NULL) // создание стека
{
head = h;
s = 0;
}
void add_link() //добавление звена
{
link* a = new link;
a->next = head;
head = a;
}
void destroy_link() //удаление звена
{
link * a = head;
head = a->next;
delete a;
}
void push (int n)
{
if ((head == NULL)||(head->capacity == 0))
{
add_link();
}
head->link_push(n);
s++;
}
int pop ()
{
if (s>0)
{
int n = (head->link_pop());
if (head->capacity == link_array_size)
{
destroy_link();
}
s--;
return n;
}
else
{
throw 0;
}
}
int back()
{
if (s>0)
{
return head->array[head->capacity];
}
else
{
throw 0;
}
}
int size()
{
return s;
}
void clear()
{
while (head!=NULL)
{
destroy_link();
}
s = 0;
}
};
int main()
{
string s;
stack Q;
while (cin>>s)
{
if (s == "push")
{
int n;
cin>>n;
Q.push(n);
cout<<"ok"<<endl;
}
if (s == "pop")
{
try
{
cout<<Q.pop()<<endl;
}
catch (int e)
{
cout<<"error"<<endl;
}
}
if (s == "back")
{
try
{
cout<<Q.back()<<endl;
}
catch (int e)
{
cout<<"error"<<endl;
}
}
if (s == "size")
{
cout<<Q.size()<<endl;
}
if (s == "clear")
{
Q.clear();
cout<<"ok"<<endl;
}
if (s == "exit")
{
cout<<"bye"<<endl;
break;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3Qgc2hvcnQgaW50IGxpbmtfYXJyYXlfc2l6ZSA9IDMwOyAvL9C60L7Qu9C40YfQtdGB0YLQstC+INGN0LvQtdC80LXQvdGC0L7QsiDQsiDQvtC00L3QvtC8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