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