Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stack>
- using namespace std;
- int main() {
- string st;
- cin >> st;
- stack <int> pool;
- int g = (int) st.size();
- for (int i=0 ; i<g ; i=i+1) {
- if (st[i]='(') {
- pool.push(1);
- }
- else if (st[i]='[') {
- pool.push(2);
- }
- else if (st[i]='{') {
- pool.push(3);
- }
- else if ((st[i]==')')&&(pool.top()=='1')) {
- pool.pop();
- }
- else if ((st[i]==']')&&(pool.top()=='2')) {
- pool.pop();
- }
- else if ((st[i]=='}')&&(pool.top()=='3')) {
- pool.pop();
- }
- else {
- printf("NOo");
- break;
- }
- printf("%d", pool.top());
- printf("%d", pool.size());
- }
- if (pool.size()!=0) {
- printf("NO");
- }
- else{
- printf("YES");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement