Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <string>
- #include <iostream>
- #include <queue>
- using std::string;
- using std::cout;
- using std::cin;
- using std::endl;
- using std::queue;
- using std::pair;
- int main()
- {
- SetConsoleOutputCP(1251);
- queue<size_t> myQueue;
- string toParce;
- getline(cin, toParce);
- size_t nBrackets = 0;
- for (auto& it : toParce)
- if (it == '(')
- nBrackets++;
- for (size_t i = 0; i < nBrackets; i++)
- {
- size_t first = toParce.find('('), second = 0;
- int n = 0;
- bool isFind = false;
- for (size_t i = first + 1; i < toParce.size() && !isFind; i++)
- {
- if (toParce[i] == '(')
- n++;
- else if (toParce[i] == ')')
- {
- if (n == 0)
- {
- second = i;
- isFind = true;
- }
- else
- n--;
- }
- }
- toParce[first] = 0;
- toParce[second] = 0;
- myQueue.push(first);
- myQueue.push(second);
- }
- cout << endl;
- while (!myQueue.empty())
- {
- cout << myQueue.front() << " ";
- myQueue.pop();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement