Advertisement
Sanlover

Untitled

Nov 7th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <string>
  3. #include <iostream>
  4. #include <queue>
  5.  
  6. using std::string;
  7. using std::cout;
  8. using std::cin;
  9. using std::endl;
  10. using std::queue;
  11. using std::pair;
  12.  
  13. int main()
  14. {
  15. SetConsoleOutputCP(1251);
  16.  
  17. queue<size_t> myQueue;
  18.  
  19. string toParce;
  20. getline(cin, toParce);
  21.  
  22. size_t nBrackets = 0;
  23. for (auto& it : toParce)
  24. if (it == '(')
  25. nBrackets++;
  26.  
  27. for (size_t i = 0; i < nBrackets; i++)
  28. {
  29. size_t first = toParce.find('('), second = 0;
  30.  
  31. int n = 0;
  32. bool isFind = false;
  33.  
  34. for (size_t i = first + 1; i < toParce.size() && !isFind; i++)
  35. {
  36. if (toParce[i] == '(')
  37. n++;
  38. else if (toParce[i] == ')')
  39. {
  40. if (n == 0)
  41. {
  42. second = i;
  43. isFind = true;
  44. }
  45. else
  46. n--;
  47. }
  48. }
  49.  
  50. toParce[first] = 0;
  51. toParce[second] = 0;
  52. myQueue.push(first);
  53. myQueue.push(second);
  54. }
  55.  
  56. cout << endl;
  57. while (!myQueue.empty())
  58. {
  59. cout << myQueue.front() << " ";
  60. myQueue.pop();
  61. }
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement