n =int(input())
d ={}for i inrange(n):
a, b =(str(x)for x ininput().split(' '))
d[b]= a
L =[]
s =str(input())while s !="dog":
L.append(d.get(s,"dog"))
s =str(input())for c in L:print(c)
題目:
代碼:
L =[]
n =int(input())for i inrange(n):
str_m =input()
num = str_m.split(' ')if num[0]=="1":
stu_id = num[1]
flag =1for temp in L:if stu_id == temp['id']:print("Students already exist")
flag =0breakelse:continueif flag ==1:
stu ={}
stu['id']= num[1]
stu['name']= num[2]
stu['score1']= num[3]
stu['score2']= num[4]
stu['score3']= num[5]
L.append(stu)print("Add success")elif num[0]=="2":
stu_id = num[1]
flag =1for temp in L:if stu_id == temp['id']:
index_id = L.index(temp)
flag =0breakelse:continueif flag ==1:print("Students do not exist")else:del L[index_id]print("Delete success")elif num[0]=="3":
stu_id = num[1]
flag =1for temp in L:if stu_id == temp['id']:
temp['score1']= num[2]
temp['score2']= num[3]
temp['score3']= num[4]print("Update success")
flag =0breakelse:continueif flag ==1:print("Students do not exist")elif num[0]=="4":
stu_id = num[1]
flag =1for temp in L:if stu_id == temp['id']:print("Student ID:"+ temp['id'])print("Name:"+ temp['name'])print("Average Score:%.1f"%((int(temp['score1'])+int(temp['score2'])+int(temp['score3']))/3))
flag =0breakelse:continueif flag ==1:print("Students do not exist")
題目:
代碼:
c =input().lower()
n =int(input())
L=[]for i inrange(n):
a =str(input())if(a.lower().count(c)>=3):
L.append(a)for i inrange(-1,-len(L)-1,-1):#還可以用L.reverse()print(L[i])
題目:
代碼:
n =int(input())
L =[]for i inrange(n):
L.append(input())
c =input()
L =sorted(list(filter(lambda i: i.startswith(c), L)))for i in L:print(i)
題目:
代碼:
n =int(input())
d ={}for i inrange(n):
a, b =map(str,input().split())
d.setdefault(b,[]).append(a)
c =input()
L =sorted(d[c])for i in L:print(i)
題目:
代碼:
import math
a, b =map(int,input().split())
l =[]for i inrange(a, b +1):for j inrange(2,int(math.sqrt(i))+2):if i % j ==0:breakelse:
ii =str(i)[::-1]ifstr(i)== ii:
l.append(i)for i in l:print(i)
題目:
代碼:
n =int(input())
L =[]for i inrange(n):
b ={}
b['n'], b['s'], b['y'], b['m'], b['d'], b['v'], b['r']=map(str,input().split())
L.append(b)
L =sorted(L, key =lambda x :(int(x['v']),-int(x['y']),-int(x['m']),-int(x['d']),-int(x['s']),-int(x['r'])))for b in L:print(b['n'], b['s'], b['y'], b['m'], b['d'], b['v'], b['r'])
題目:
代碼:
import re
n =int(input())
d ={}for i inrange(n):
a =input()
d[''.join(re.findall('[A-Z]+', a))]= a
for i insorted(d):print(d[i])