Advertisement
TimxAG

Untitled

Sep 10th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int IMAX = 1000000;
  4. int a[2 * IMAX];
  5. int main()
  6. {
  7. int n;
  8. scanf("%d",&n);
  9. int i=1;
  10. // vector <int> b;
  11. while (n--)
  12. {
  13. /* cin >> q;
  14. if (q>0) a.push_back(q);
  15. if (q==0) { int count = a.size(); for (k=0;k<count;k++) a.push_back(a[k]); }
  16. if (q==-1) { printf("%d ",a[a.size()-1]); a.pop_back(); }
  17. */
  18. int q;
  19. scanf("%d",&q);
  20. if (q>0) a[i++]=q;
  21. else
  22. if (q==-1) { i--; printf("%d ",a[i]); }
  23. else
  24. if (q==0)
  25. {
  26. if (i - 1 <= n)
  27. {
  28. int uk= min(i - 1, n);
  29. for (int k = 1; k <= uk; k++)
  30. {
  31. a[i] = a[i-uk];
  32. i++;
  33. }
  34. }
  35. }
  36. // cout << q << " " << a[i];
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement