Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <string>
  6. #include <cstdlib>
  7. #include <deque>
  8. using namespace std;
  9.  
  10.  
  11. int main()
  12. {
  13. int n, k;
  14. cin >> n >> k;
  15. vector<deque<int>> Stek(n+1);
  16.  
  17. for (int i(0);i < k;i++)
  18. {
  19. string s;
  20. string s0("");
  21. string s1("");
  22. cin >> s;
  23. int a, b;
  24. int j(0), p, q;
  25. if (s[0] == 'P')
  26. if (s[1] == 'O')
  27. {
  28. a = s.find('(');
  29. b = s.find(')');
  30. s0 = s.substr(a + 1, b - a - 1);
  31. p = atoi(s0.c_str());
  32. cout << Stek[p][0] <<" ";
  33. Stek[p].pop_front();
  34. if(Stek[p].empty())
  35. Stek[p].shrink_to_fit();
  36. }
  37. else
  38. {
  39. a = s.find('(');
  40. b = s.find(',');
  41. s0 = s.substr(a+1, b-a-1);
  42. p = atoi(s0.c_str());
  43. a = s.find(')');
  44. s1 = s.substr(b + 1, a - b - 1);
  45. q = atoi(s1.c_str());
  46. Stek[p].push_back(q);
  47. }
  48. else
  49. {
  50. a = s.find('(');
  51. b = s.find(')');
  52. s0 = s.substr(a + 1, b - a - 1);
  53. p = atoi(s0.c_str());
  54. cout << Stek[p][0] <<" ";
  55. }
  56. }
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement