Baekjoon #4949

Baekjoon #4949

1개의 풀이 · C++

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    string str;
    while (1) {
        getline(cin, str);
        if (str == ".") break;
        
        bool isBalanced = true;
        stack<char> st;
        
        for (char c : str) {
            if (!isBalanced) break;
            switch (c) {
                case '(':
                    st.push(c);
                    break;
                case ')':
                    if (st.empty() || st.top() != '(') isBalanced = false;
                    else st.pop();
                    break;
                case '[':
                    st.push(c);
                    break;
                case ']':
                    if (st.empty() || st.top() != '[') isBalanced = false;
                    else st.pop();
                    break;
                default:
                    break;
            }
        }
        if (isBalanced && st.empty()) cout << "yes\n";
        else cout << "no\n";
    }
    return 0;
}

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.