taky0315   2년 전

# 테스트 케이스를 총 3가질로 나누었다

# 1. () [] 인경우

# 2. (x), [x] 인경우

# 3. (x,y) 인경우

list = []

command = input()

error = 0

for (i,a) in enumerate(command):

if a == '(' or a == '[':

list.append(a)

elif a ==')':

if len(list) > 0 and list[-1] == '(':

list.pop()

list.append(2)

elif len(list) > 1 and list[-2] == '(':

value = list.pop()

list.pop()

list.append(value * 2)

elif len(list) > 2 and list[-3] == '(':

val1 = list.pop()

val2 = list.pop()

list.pop()

list.append(2 * (val1 + val2))

else :

error = 1

break

elif a ==']':

if len(list) > 0 and list[-1] == '[':

list.pop()

list.append(3)

elif len(list) > 1 and list[-2] == '[':

value = list.pop()

list.pop()

list.append(value * 3)

else:

error = 1

break

result = 0

if error == 0 :

for i in list:

result += i

print(result)

else :

print(0)

# 테스트 케이스를 총 3가질로 나누었다

# 1. () [] 인경우

# 2. (x), [x] 인경우

# 3. (x,y) 인경우

list = []

command = input()

error = 0

for (i,a) in enumerate(command):

if a == '(' or a == '[':

list.append(a)

elif a ==')':

if len(list) > 0 and list[-1] == '(':

list.pop()

list.append(2)

elif len(list) > 1 and list[-2] == '(':

value = list.pop()

list.pop()

list.append(value * 2)

elif len(list) > 2 and list[-3] == '(':

val1 = list.pop()

val2 = list.pop()

list.pop()

list.append(2 * (val1 + val2))

else :

error = 1

break

elif a ==']':

if len(list) > 0 and list[-1] == '[':

list.pop()

list.append(3)

elif len(list) > 1 and list[-2] == '[':

value = list.pop()

list.pop()

list.append(value * 3)

else:

error = 1

break

result = 0

if error == 0 :

for i in list:

result += i

print(result)

else :

print(0)

# 테스트 케이스를 총 3가질로 나누었다

# 1. () [] 인경우

# 2. (x), [x] 인경우

# 3. (x,y) 인경우

list = []

command = input()

error = 0

for (i,a) in enumerate(command):

if a == '(' or a == '[':

list.append(a)

elif a ==')':

if len(list) > 0 and list[-1] == '(':

list.pop()

list.append(2)

elif len(list) > 1 and list[-2] == '(':

value = list.pop()

list.pop()

list.append(value * 2)

elif len(list) > 2 and list[-3] == '(':

val1 = list.pop()

val2 = list.pop()

list.pop()

list.append(2 * (val1 + val2))

else :

error = 1

break

elif a ==']':

if len(list) > 0 and list[-1] == '[':

list.pop()

list.append(3)

elif len(list) > 1 and list[-2] == '[':

value = list.pop()

list.pop()

list.append(value * 3)

else:

error = 1

break

result = 0

if error == 0 :

for i in list:

result += i

print(result)

else :

print(0)

댓글을 작성하려면 로그인해야 합니다.