Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- string s;
- cin >> s;
- bool flag = true;
- string s1;
- for(const auto& x : s){
- if(x == '(' || x == '[' || x == '{'){
- s1.push_back(x);
- } else{
- if(s1.empty()){
- flag = false;
- break;
- }
- if(x - s1.back() == 1 || x - s1.back() == 2){
- s1.pop_back();
- } else{
- flag = false;
- break;
- }
- }
- }
- if(!s1.empty()){
- flag = false;
- }
- if(flag){
- cout << "yes\n";
- } else{
- cout << "no\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment