牛客华为机试HJ70
作者:互联网
1. 题目描述
2. Solution 1
1、思路分析
dim(A) = (m, n), dim(B) = (n, p)
AB = mp
2、代码实现
import sys
if sys.platform != "linux":
sys.stdin = open("input/HJ70.txt")
while True:
try:
n = int(input().strip())
dims = []
res = 0
for _ in range(n):
dims.append(list(map(int, input().strip().split())))
s = input().strip()
s_list = list(s)
for i in range(len(s_list)):
if s_list[i].isalpha():
s_list[i] = dims[ord(s_list[i]) - ord('A')]
stack = []
for x in s_list:
if x == ')':
m2_r, m2_c = stack.pop()
m1_r, m1_c = stack.pop()
res += m1_r * m1_c * m2_c
stack.append([m1_r, m2_c])
elif isinstance(x, list):
stack.append(x)
print(res)
except:
break
标签:input,m2,list,strip,牛客,m1,HJ70,机试,stack 来源: https://www.cnblogs.com/junstat/p/16172606.html