https://www.acmicpc.net/problem/2504
진짜 질문게시판에 있는 반례도 다 돌아가던대 왜ㅐㅐㅐㅐ
| 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include <iostream> #include <stack> #include <string> using namespace std; int main() { int len, x = 0, y = 0; int tot = 0; int mul = 1; string str; stack<int> st; char c; cin >> str; len = str.length(); for (int j = 0; j < len; j++) { c = str[j]; if (c == '(') { x++; mul = mul * 2; st.push(c); if (j + 1 < len) if (str[j + 1] == ')') tot = tot + mul; } else if (c == ')') { mul = mul / 2; if (st.size() == 0) break; else if (st.top() != '(') break; st.pop(); x--; } else if (c == '[') { y++; mul = mul * 3; st.push(c); if (j + 1 < len) if (str[j + 1] == ']') tot = tot + mul; } else if (c == ']') { mul = mul / 3; if (st.size() == 0) break; else if (st.top() != '[') break; st.pop(); y--; } else break; } if (st.size() != 0 || x != 0 || y != 0) cout << 0 << endl; else cout << tot<<endl; } |
()]
와~~~진짜
감사합니다