jae_coding

(백준 자료구조 문제풀이)10799번 쇠막대기 본문

알고리즘 문제/자료구조 문제

(백준 자료구조 문제풀이)10799번 쇠막대기

재코딩 2022. 7. 19. 14:29
반응형

문제

 

문제 링크

 

코드

import sys
from collections import deque
input = sys.stdin.readline

input_string = deque(input().strip())
count = 0
result = 0
primary_string = ""
while len(input_string) != 0:
    temp = input_string.pop()
    if temp == ")":
        count += 1
    else:
        if primary_string == "(":
            count -= 1
            result += 1
        else:
            count -= 1
            result += count

    primary_string = temp

print(result)
반응형
Comments