【python】coedeforces 785A

来源:互联网 发布:共青团中央 知乎 编辑:程序博客网 时间:2024/06/06 04:19

题目并不难,但第一种写法所占内存过大,所以想了第二种写法

第一种写法 内存13920kb

n = int(raw_input())importance = []for i in range(n):    importance.append(raw_input())result = 0for 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 += 20print 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 = 0for i in range(n):    result += get_score(raw_input())print result


原创粉丝点击