fork download
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<stack>
  5.  
  6. using namespace std;
  7.  
  8. #define s(t) scanf("%d",&t)
  9. #define p(t) printf("%d\n",t)
  10.  
  11. int main()
  12. {
  13. int n,p,numbookstoremove;
  14. char cb[16];
  15. s(n);
  16. stack<int> minbookstoremove;
  17. stack<int> probstosolve;
  18. stack<string> books;
  19. string booktopick;
  20. while(n--)
  21. {
  22. s(p);
  23. if(p==-1)
  24. {
  25. numbookstoremove=minbookstoremove.top();
  26. while(!minbookstoremove.empty() && minbookstoremove.top()!=0)
  27. {
  28. minbookstoremove.pop();
  29. probstosolve.pop();
  30. books.pop();
  31. }
  32. booktopick=books.top();
  33. printf("%d %s\n",numbookstoremove,booktopick.c_str());
  34. minbookstoremove.pop();
  35. probstosolve.pop();
  36. books.pop();
  37. }
  38. else
  39. {
  40. scanf("%s",cb);
  41. if(p!=0)
  42. {
  43. string b(cb);
  44. if(minbookstoremove.empty())
  45. {
  46. minbookstoremove.push(0);
  47. books.push(b);
  48. probstosolve.push(p);
  49. }
  50. else
  51. {
  52. if(p<probstosolve.top())
  53. {
  54. minbookstoremove.push(0);
  55. books.push(b);
  56. probstosolve.push(p);
  57. }
  58. else
  59. {
  60. minbookstoremove.push(minbookstoremove.top()+1);
  61. books.push(b);
  62. probstosolve.push(probstosolve.top());
  63. }
  64. }
  65. }
  66. }
  67. }
  68. return 0;
  69. }
Runtime error #stdin #stdout 0.02s 2824KB
stdin
6
1 a
2 b
0 c
1 d
-1
-1
stdout
Standard output is empty