0
0

AtCoder初心者 DailyTrainingメモ 2023/11/26

Posted at

ABC242 B-問題

242B.png

ポイント
受け取る文字列をリストで取得し、ソートする。

242B.py
# リストで受け取る
S = list(input())

# リストをソートして昇順に文字を並べ替える
S.sort()

# "".join(S) でリストを結合する
print("".join(S))

ABC294 C-問題

294C.png

ポイント
・リストAとBを合わせてソートする C = sorted(A + B)
・enumerate を使って、リストCの各値とインデックス +1 をDICへ格納する

294C.py
N,M = map(int,input().split())
# リストで受け取る
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# リストAとBを合わせてソートする
C = sorted(A + B)

# enumerateで 文字とインデックス+1 を辞書に格納する
DIC = {}
for i, c in enumerate(C):
    DIC[c] = i + 1
# DIC = {c: i + 1 for i, c in enumerate(C)}


for a in A:
    print(DIC[a])
for b in B:
    print(DIC[b])
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