#include <iostream.h>
#include <string.h>

#define MAX 40
// Program z implementacja stosu - kolejki LIFO (Last In First Out)

typedef char Elem[MAX];

typedef struct lifo{
  Elem napis;
  struct lifo *nast;
} Lifo;

Lifo *Stos=NULL;;
                        
// wlozenie elementu na stos
void Push(Elem napis){
  Lifo *nowy=new Lifo;
  strcpy(nowy->napis,napis);
  nowy->nast=Stos;
  Stos=nowy;
}

// zdjecie elementu ze stosu
void Pull(Elem target){
  Lifo *n=Stos->nast;
  if ( Stos ){
    strcpy(target,Stos->napis);
    delete Stos;
    Stos=n;
  }
}

int main(){
  Elem tekst;

  while ( cin ){
    cout << "Podaj slowo (max " << MAX-1 
	 << " liter) ctr-Z aby skonczyc: "<<endl;
    cin >> tekst;
    if ( strcmp(tekst,"") )
      Push(tekst);
  }
  
  while ( Stos ){
    Pull(tekst);
    cout << " zdejmuje ze stosu slowo " << tekst << endl;
  }
  cout << "Stos pusty!" << endl;
  return 0;
} 
  

