쇠막대기

이세진·2022년 4월 15일
0

코테준비

목록 보기
33/87

생성일: 2022년 1월 24일 오후 5:23

구현 코드

# 쇠막대기
import sys
#sys.stdin = open("input2.txt", "rt")
word = input()
stick = []
for x in word:
    stick.append(x)

last = ""
res = 0
numberOfStick = 0
for x in stick:
    if x == '(':
        numberOfStick += 1
        last = x
    else:
        if last + x == "()":
            numberOfStick -= 1
            res += numberOfStick
            last = x
        elif last + x == "))":
            res += 1
            numberOfStick -= 1
            last = x
    
print(res)
profile
나중은 결코 오지 않는다.

0개의 댓글