Created
July 31, 2019 03:52
-
-
Save surinoel/225214fc1d6fc618f3ea615c20abd386 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stack> | |
#include <sstream> | |
#include <iostream> | |
using namespace std; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
string s; | |
for (;;) { | |
getline(cin, s); | |
if (s == ".") break; | |
stack<char> st; | |
bool ok = true; | |
for (int i = 0; i < s.length() - 1; i++) { | |
if (s[i] == '(' || s[i] == '[') { | |
st.push(s[i]); | |
} | |
else if (s[i] == ')') { | |
if (st.empty() || st.top() != '(') { | |
ok = false; | |
} | |
else { | |
st.pop(); | |
} | |
} | |
else if (s[i] == ']') { | |
if (st.empty() || st.top() != '[') { | |
ok = false; | |
} | |
else { | |
st.pop(); | |
} | |
} | |
} | |
if (ok && st.empty()) { | |
cout << "yes\n"; | |
} | |
else { | |
cout << "no\n"; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment