algorithm'''problem solve
[백준]4949-균형잡힌 세상(설명X)
JunHwa Park
2020. 2. 2. 02:18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <cstdio> #include <stack> #include <iostream> #include <cstring> using namespace std; int main() { while (true) { stack<char> stk; char str[100]; scanf("%[^\n]", str); int size = strlen(str); cin.ignore(); if (str[0] == '.' && size == 1) break; bool equal = true; for (size_t i = 0; i < size; i++) { if (str[i] == '(') stk.push('('); else if (str[i] == '[') stk.push('['); else if (str[i] == ')') { if (stk.size() == 0 || stk.top() != '(') equal = false; else stk.pop(); } else if (str[i] == ']') { if (stk.size() == 0 || stk.top() != '[') equal = false; else stk.pop(); } else if (str[i] == '.') break; } if (equal && stk.size() == 0) printf("yes\n"); else printf("no\n"); } return 0; } | cs |