Baekjoon #10799

Baekjoon #10799

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);

    int total = 0;
    int pipe_stack = 0;
    bool is_opened = true;

    char ch;
    while (cin >> ch) {
        if (ch == '(') {
            // start of pipe
            pipe_stack++;
            is_opened = true;
        } else if (ch == ')' && is_opened) {
            // laser
            pipe_stack--;
            total += pipe_stack;
            is_opened = false;
        } else if (ch == ')' && !is_opened) {
            // end of pipe
            pipe_stack--;
            total += 1;
            is_opened = false;
        }
    }

    cout << total << '\n';

    return 0;
}

SOLUTION DESCRIPTION

풀이 설명

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