麻煩各位熟悉python的大大有空幫忙一下
用try except的寫法,在最後的一筆測資一直造成TLE
但改用第二種寫法,就AC了
第一種寫法:try except(最後一筆測資TLE)
#coding=UTF-8 import sys Dict={"0 1 0 1":"A","0 1 1 1":"B","0 0 1 0":"C","1 1 0 1":"D","1 0 0 0":"E","1 1 0 0":"F"} while True: try: N=input() ans="" for i in range(int(N)): sIn=input() ans +=Dict[sIn] print (ans) except EOFError: break
第二種寫法:AC
#coding=UTF-8 import sys Dict={"0 1 0 1":"A","0 1 1 1":"B","0 0 1 0":"C","1 1 0 1":"D","1 0 0 0":"E","1 1 0 0":"F"} #print (Dict["0 1 0 1"]) for i in sys.stdin: n = int(i) ans = "" for i in range(n): sIn=sys.stdin.readline() sIn=sIn.replace("\r","").replace("\n","") ans +=Dict[sIn] print (ans)
以上謝謝!!
站內的範例也是
import sys
for s in sys.stdin:
print('hello, '+s)