我想解决编码 games.com 中的哑剧挑战。我的代码可以通过所有测试,但不能通过优化测试。
我试图删除所有无用的函数,例如解析为字符串,但问题出在我的思考方式上。
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = int(input()) # Number of elements which make up the association table.
q = int(input())
# Number Q of file names to be analyzed.
dico = {}
# My function
def check(word):
for item in dico:
if(word[-len(item)-1:].upper() == "."+item.upper()):
return(dico[item])
return("UNKNOWN")
for i in range(n):
# ext: file extension
# mt: MIME type.
ext, mt = input().split()
dico[ext] = mt
for i in range(q):
fname = input()
fname = fname
print(check(fname))
# Write an action using print
# To debug: print("Debug messages...", file=sys.stderr)
#print("Debug message...", file=sys.stderr)
失败进程已超时。这可能意味着您的解决方案没有优化到足以处理某些情况。
红糖糍粑
SMILET
相关分类