你的代码仅仅处理了一个测试用例,没有循环处理多个测试用例
最大映射编程题:http://www.nowcoder.com/test/question/4bba9f2ab638483093e34377dd9b3e91?pid=1649268&tid=3818288
一直提示:你的代码仅仅处理了一个测试用例,没有循环处理多个测试用例
求解答测试数据的具体格式,
def solution(inp_str):
d = {}.fromkeys(('A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'H'), 0)
for line in inp_str:
for i, ch in enumerate(line[::-1]):
d[ch] += 10**i
sorted_d = sorted(d.items(), key=lambda x: x[1], reverse=True) # 按照value排序
ret = 0
i = 9
for e in sorted_d:
ret += e[1]*i
i -= 1
print ret
import sys
while True:
try:
line = sys.stdin.readline()
if line=='':
break
n = int(line)
inp_str = []
for i in range(n):
inp = sys.stdin.readline()
inp_str.append(inp)
solution(inp_str)
except:
break

