Korotkodul

mosh e

Feb 27th, 2022 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17. for (auto x: v) cout<<x<<' ';
  18. cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22. for (auto x: v) cout<<x<<' ';
  23. cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28. for (auto x: v) cv(x);
  29. cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33. for (bool x: v) cout<<x<<' ';
  34. cout<<"\n";
  35. }
  36.  
  37.  
  38. int main()
  39. {
  40. ios::sync_with_stdio(0);
  41. cin.tie(0);
  42. cout.tie(0);
  43. int t; cin>>t;
  44. for (int act=0;act<t;++act){
  45. queue <int> Q;
  46. stack <int> S;
  47. bool st=1, qu=1;
  48. int n; cin>>n;
  49. for (int i = 0 ;i < n;++i){
  50. int d;
  51. string cmd; cin>>cmd>>d;
  52. if (cmd == "push"){
  53. Q.push(d);
  54. S.push(d);
  55. }
  56. else{
  57. if (Q.front() != d){
  58. qu=0;
  59. }
  60. Q.pop();
  61.  
  62. if (S.top() != d){
  63. st = 0;
  64. }
  65. S.pop();
  66. }
  67. }
  68. if (st && qu){
  69. cout<<"both\n";
  70. }else if (st){
  71. cout<<"stack\n";
  72. }else if (qu){
  73. cout<<"queue\n";
  74. }else cout<<"none\n";
  75. }
  76. }
  77.  
Add Comment
Please, Sign In to add comment