题目并不难,但第一种写法所占内存过大,所以想了第二种写法
第一种写法 内存13920kb
n = int(raw_input())
importance = []
for i in range(n):
importance.append(raw_input())
result = 0
for item in importance:
if item == "Tetrahedron":
result += 4
if item == "Cube":
result += 6
if item == "Octahedron":
result += 8
if item == "Dodecahedron":
result += 12
if item == "Icosahedron" :
result += 20
print result
第二种写法 3408kb
def get_score(item):
if item == "Tetrahedron":
return 4
if item == "Cube":
return 6
if item == "Octahedron":
return 8
if item == "Dodecahedron":
return 12
if item == "Icosahedron" :
return 20
n = int(raw_input())
result = 0
for i in range(n):
result += get_score(raw_input())
print result