發現牛客網的考研題不錯,趕緊刷刷
阿新 • • 發佈:2018-07-08
break while class pop adl 升序 bsp put lap
題目:
#下面這一段用一個txt來保存input的信息來模擬input.最後提交代碼時候刪除這一段即可. a9999=open(‘1.txt‘,‘r‘) def input(): return a9999.readline() while 1: try: a=int(input()) b=int(input()) if b==0: c=‘降序‘ else: c=‘升序‘ out=[] if b==0: for i in range((a)): tmpView Code=input().split() name=tmp[0] score=tmp[1] out.append((name,score)) out2=[] while len(out)>0: i=0 for j in range(len(out)): if int(out[j][1])>int(out[i][1]): i=j out2.append(out[i]) out.pop(i) for i in range(len(out2)): print(out2[i][0]+‘ ‘+out2[i][1]) else: for i in range((a)): tmp=input().split() name=tmp[0] score=tmp[1] out.append((name,score)) out2=[] whilelen(out)>0: i=0 for j in range(len(out)): if int(out[j][1])<int(out[i][1]): i=j out2.append(out[i]) out.pop(i) for i in range(len(out2)): print(out2[i][0]+‘ ‘+out2[i][1]) except: break
View Code
發現牛客網的考研題不錯,趕緊刷刷