[프로그래머스] 올바른 괄호

leejihun·2022년 11월 13일
0

알고리즘

목록 보기
39/50

https://school.programmers.co.kr/learn/courses/30/lessons/12909

#include<string>
#include <iostream>
#include<stack>
using namespace std;

bool solution(string s)
{
    bool answer = false;

    stack<int> a, b;

    for (int i = 0; i < s.length(); i++)
    {

        if (s[i] == '(')
        {
            a.push(1);
        }
        else if (!a.empty() && s[i] == ')')
        {
            a.pop();
        }

        else
        {
            a.push(2);
            break;
        }

    }

    if (a.empty())
    {
        answer = true;
    }




    return answer;

}

void main()
{
    string a;
    cin >> a;
    cout << solution(a);

}

스택 기본문제

profile
U+221E

0개의 댓글