Hemofobia

Untitled

Nov 25th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class array{
  7.     private:
  8.         int amount;     //iloΕ›Δ‡ elementΓ³w tablicy
  9.         int *tab;
  10.         int sizetab;    //rozmiar tablicy
  11.     public:
  12.         array(int x){
  13.             sizetab=x;
  14.             amount=-1;
  15.             tab=new int[sizetab];
  16.         }
  17.  
  18.     void add_element(int sizetab){
  19.         if(amount<=1000000){
  20.             if(sizetab<=1000000 && sizetab>=0){
  21.                 tab[amount]=sizetab;
  22.                 ++amount;
  23.                 return;
  24.             }
  25.         }
  26.     }
  27.  
  28.     void add_tab(){
  29.         int *tab2=new int[sizetab];
  30.         for(int i=0; i<sizetab; i++){
  31.             tab2[i]=tab[i];
  32.         }
  33.     }
  34.     int get_amount(){
  35.         return amount+1;
  36.     }
  37.     void delete_first(){
  38.         if(amount>0)
  39.         for(int i=0; i<=amount; i++){
  40.             tab[i]=tab[i+1];
  41.         }
  42.         --amount;
  43.         return;
  44.     }
  45.  
  46.     int first(){
  47.         return tab[0];
  48.     }
  49. };
  50.  
  51. int main(){
  52.     int num;
  53.     int tc;
  54.     array tab(1);
  55.     scanf("%d", &tc);
  56.     for(int t=0; t<tc; t++){
  57.         char c=' ';
  58.         while(c!='A' && c!='D' && c!='S')
  59.         c=getchar();
  60.         if(c=='A'){
  61.             scanf("%d", &num);
  62.             tab.add_element(num);
  63.         }
  64.         else if(c=='D'){
  65.             if(tab.get_amount()==0){
  66.                 printf("EMPTY\n");
  67.                 continue;
  68.             }
  69.             else
  70.                 cout<<tab.first()<<endl;
  71.                 tab.delete_first();
  72.             }
  73.         else{
  74.             cout<<tab.get_amount()<<endl;
  75.         }
  76.     }
  77. return 0;
  78. }
Add Comment
Please, Sign In to add comment