Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <stack>
- using namespace std;
- int main()
- {
- string o;
- cin>>o;
- stack<char>p;
- for(int y=0; y<o.size(); y+=1){
- if(o[y] == '(' or o[y] == '{' or o[y] == '[') {
- p.push(o[y]);
- }
- else {
- if(o[y] == ')' and !p.empty() and p.top() == '(') {
- p.pop();
- }
- else if(o[y] == '}' and !p.empty() and p.top() == '{') {
- p.pop();
- }
- else if(o[y] == ']' and !p.empty() and p.top() == '[') {
- p.pop();
- }
- else {
- cout << "NO" << endl;
- return 0;
- }
- }
- }
- if(p.empty()) {
- cout << "YES" << endl;
- }
- else {
- cout << "NO" << endl;
- }
- return 0;
- }
- // ]]][[[[
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement