SHARE
TWEET

Untitled

a guest May 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. //int mat[105][25005];
  5. int v[25005];
  6. //bool remov[25005];
  7. int n,m;
  8. stack <int>st;
  9. void make_v()
  10. {
  11.     while(!st.empty())
  12.     {
  13.         v[++m]=st.top();
  14.         st.pop();
  15.     }
  16. }
  17. int main()
  18. {
  19.     freopen("numere2.in","r",stdin);
  20.     freopen("numere2.out","w",stdout);
  21.     int x,cnt=0;
  22.     scanf("%d",&n);
  23.     for(int i=1; i<=n; ++i)
  24.     {
  25.         scanf("%d",&x);
  26.         if(!st.empty()&&st.top()==x)
  27.         {
  28.             cnt++;
  29.             st.pop();
  30.         }
  31.         else
  32.             st.push(x);
  33.     }
  34.  
  35.     printf("%d\n",cnt);
  36.     make_v();
  37.     for(int i=m;i>=1;--i)
  38.     {
  39.         printf("%d ",v[i]);
  40.     }
  41.     return 0;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top