Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int main()
- {
- string st = "({[]})";
- vector<char> a;
- int p = st.size() - 1;
- for (int i = 0; i < p; i++)
- {
- a.push_back(st[i]);
- }
- vector<char> b;
- bool r = true;
- int i = 0;
- if ((a[i] == ')') || (a[i] == '}') || (a[i] == ']'))
- {
- r = false;
- }
- for (i = 1; i < a.size(); i++)
- {
- if ((a[i] == '(') || (a[i] == '{') || (a[i] == '['))
- {
- b.push_back(a[i]);
- }
- if (a[i] == ')')
- {
- if (a[i - 1] == '(')
- {
- b.erase(b.end()-1);
- }
- else
- {
- r = false;
- }
- }
- if (a[i] == '}')
- {
- if (a[i - 1] == '{')
- {
- b.erase(b.end()-1);
- }
- else
- {
- r = false;
- }
- }
- if (a[i] == ']')
- {
- if (a[i - 1] == '[')
- {
- b.erase(b.end()-1);
- }
- else
- {
- r = false;
- }
- }
- cout << r << endl;
- system("pause");
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement