[CodeUp] #3129-올바른 괄호 2(스택)

chrmqgozj·2022년 2월 3일
0

CodeUp

목록 보기
39/48
#include <iostream>
#include <stack>
using namespace std;

stack<char> s;
int main(){
    string in;
    cin >> in;

    for(int i=0;i<in.size();i++){
        s.push(in[i]);
    }

    int cnt1 = 0;
    int cnt2 = 0;
    char temp;
    int chk = 1;
    while(!s.empty()){
        temp = s.top();
        s.pop();

        if(temp == ')'){
            cnt2++;
        }
        else{
            cnt1++;
        }
        if(cnt2<cnt1){
            chk = 0;
        }
    }

    if(temp == ')'){
        chk = 0;
    }

    if(chk == 1){
        cout << "good";
    }
    else{
        cout << "bad";
    }

}

0개의 댓글

관련 채용 정보