0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Atcoder】ABC 128 B問題

Posted at

コンテスト名

AtCoder Beginner Contest 128

考えたこと

n=int(input())
l=[]
for i in range(n):
    s,p=map(str,input().split())
    p=int(p)
    l.append([s,p])

B問題だし余裕だろ!!...と思ったが

辞書順に早いかどうかをどうやって判別するか?

dictionary_sort = sort(l, key=lambda x: x[0])
print(dictionary_sort)

出力

[['kazan', 50], ['kazan', 35], ['khabarovsk', 20], ['khabarovsk', 40], ['moscow', 10], ['moscow', 60]]

なんか普通にsortされた。
文字列をsortすると辞書順になるみたいだね*1

ここからどうやって文字列が同じ時数字が大きい順に並べるか迷ったが。。。

sort(key=lambda x:(x[0],-x[1]))

*2

で行けるみたい。

参考

*1

*2

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?