Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- #include <string>
- #include <cstring>
- using namespace std;
- int main(){
- stack <char> sym;
- string s;
- getline(cin,s);
- int count = 0;
- for (auto c : s){
- if (c == '(' || c == '{' || c == '['){
- sym.push(c);
- }
- else if(c == ')'){
- if (sym.top() == '('){
- sym.pop();
- }
- else{
- count += 1;
- }
- }
- else if(c == ']'){
- if (sym.top() == '[') {
- sym.pop();
- }
- else{
- count += 1;
- }
- }
- else if(c == '}') {
- if ( sym.top() == '{') {
- sym.pop();
- }
- else {
- count += 1;
- }
- }
- }
- if (sym.empty() && count == 0){
- cout << "YES";
- }
- else{
- cout << "NO";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement