uva 10420 List of Conquests
Dec 26, 2022
uva過,codingFrenzy的測資有問題不知道是不是載到舊版的XD。
以下是我的想法。
country = {}
person = []
t = int(input())
while(t):
data = input().split(" ")
where, *who = data
if who not in person:
try:
country[where] += 1
except KeyError:
country[where] = 1
person.append(who)
t = t-1
result = sorted(country.items(), key = lambda x: x[0])
for thing in result:
print(thing[0], thing[1])
先存取測資。如果該筆資料的人沒有出現在person內,就把該人的國家數目+1。由於輸出的國家要照字母順序排列,因此進行排序。最後輸出結果。