쇠막대기


Define input, output

  • Input: 쇠 막대기의 시작, 끝, 레이저 포인트에 대한 array
  • Output: 레이저로 잘린 쇠막대기의 총 개수

source code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import sys


points = list(sys.stdin.readline().strip())

total = 0
remain = []
for i, point in enumerate(points):
    if point == ")":
        j = remain.pop()
        if i - j == 1:
            total += len(remain)
        else:
            total += 1
    else:
        remain.append(i)

print(total)```
Built with Hugo
Theme Stack designed by Jimmy