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?

More than 3 years have passed since last update.

ABC217 C - Inverse of Permutation を解いた

Last updated at Posted at 2021-10-19

abc217c_1.png
abc217c_2.png
abc217c_3.png

文章の通りに打った。

abc217c_r1.py
N = int(input())
P = list(map(int,input().split()))

lis =[0]*N

for i in range(N):
    lis[P[i]-1] = str(i+1)

print(" ".join(lis))

別解

abc217c_r2.py
N = int(input())
P = list(map(int,input().split()))
num = [0]*N

for i in range(N):
    num[P[i]-1] = i+1

print(" ".join(map(str,num)))

学んだこと
map は for 文なしで一括変換が出来るって代物だと初めて知った。

map(int,input().split()) は分割した入力 input().split() を一括で int(整数) に変換しているわけだ。
以下を参考にすると、そこそこ早いらしい。

っと言うことは以下の記述も同じ意味になり、
何やっているのかイメージしやすい

change_format.py
#approach1
lis = list(map(lambda x:str(x),lis))

#approach2
lis = list(map(str,lis))

あれから。。
文字で扱うのも良いが、
以下のようにも書けるようだ。

abc217c.py
N = int(input())
P = list(map(int,input().split()))
S = [0]*N

for i in range(N):
    S[P[i]-1] = i+1

print(*S)
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?