From d341e56fee3dbccaf28b5da42b31cb2ac958ab1f Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 1 Jun 2026 16:46:53 +0900 Subject: [PATCH] =?UTF-8?q?4949=20:=20=EA=B7=A0=ED=98=95=EC=9E=A1=ED=9E=8C?= =?UTF-8?q?=20=EC=84=B8=EC=83=81=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week2/BOJ4949/BOJ4949_V1.cpp | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/week2/BOJ4949/BOJ4949_V1.cpp diff --git a/src/week2/BOJ4949/BOJ4949_V1.cpp b/src/week2/BOJ4949/BOJ4949_V1.cpp new file mode 100644 index 0000000..4e38f88 --- /dev/null +++ b/src/week2/BOJ4949/BOJ4949_V1.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; +bool check(string s) { + stack stk; + + for (int i = 0; i < s.length(); i++) { + if (s[i] == '(' || s[i] == '[') + stk.push(s[i]); + else if (s[i] == ')') { + if (stk.empty() || stk.top() != '(') + return false; + stk.pop(); + } else if (s[i] == ']') { + if (stk.empty() || stk.top() != '[') + return false; + stk.pop(); + } + } + + return stk.empty(); +} +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + string s; + vector ret; + while(getline(cin, s)) { + if (s == ".") + break; + ret.push_back(check(s)); + } + + for (int i = 0; i < ret.size(); i++) { + if (ret[i]) + cout << "yes\n"; + else + cout << "no\n"; + } +} \ No newline at end of file