Baekjoon #9012

Baekjoon #9012

3개의 풀이 · C++, Java, Python

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
#include<bits/stdc++.h>

using namespace std;

string solve(string str) {
    stack<int> st; 
    for(int i=0;i<(int)str.size();i++){
        if(str[i] == '(') st.push('(');
        else {
            if(st.empty()) return "NO";
            st.pop();
        }
    }

    if(st.empty()) return "YES";
    return "NO";
}

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

    int T; cin >> T;
    while(T--) {
        string s; cin >> s;
        cout << solve(s) << '\n';
    }

    return 0;
}

SOLUTION DESCRIPTION

풀이 설명

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