1
0

歴史を作る時間 (paizaランク C 相当)

Last updated at Posted at 2024-03-29

タプルのやり方を完全に忘れてたので、調べつつ対応しました
まあ、中身としてはうーんnamesは必要ない気がします。。。
一応出したけど。
historiesは内包表記ができなさそうなので、普通に。タプル化して配列に入れてます。
タプル化したやつをどうやっていれるかってことでちょっと迷ったけども。

その後は、sortedしたやつをそのままプリントするだけですね。
クエリじゃない問題だと思ったのですが案の定でした。

N,K = map(int,input().split())
names = {input() for _ in range(N)}
histories = []
for i in range(K):
    event,charge = input().split()
    histories[i] = (int(event),charge)

for year, name in sorted(histories):
    print(name)

とりあえず以上です。

すみません、間違えました。。。
これだとランタイムエラーが発生して失敗します。

N,K = map(int,input().split())
names = {input() for _ in range(N)}
#あらかじめ配列の個数分のNoneが必要
histories = [None] * K
for i in range(K):
    event,charge = input().split()
    histories[i] = (int(event),charge)

for year, name in sorted(histories):
    print(name)
1
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
1
0