LoginSignup
0
0

More than 1 year has passed since last update.

ABC215 C - One More aab aba baa から学んだ

Posted at

abc215_1.png
abc215_2.png

重複なし並び替えを実行して K 番目を出力する。
ただし、重複する文言が出てくるので set する

abc215c.py
from itertools import permutations
S,K = input().split()
K = int(K)
lis=[]
for i in permutations(range(len(S)),len(S)):
    nums = list(i)
    s =""
    for j in range(len(S)):
        s += S[nums[j]]
    lis.append(s)
lis = sorted( list(set(lis)) )
#print(lis)
print(lis[K-1])

解答を眺めると、S そのものを permutation で
リストするやり方もあって、面白かった。

abc215c_r1.py
from itertools import permutations
S,K = input().split()
K = int(K)
lis=["".join(i) for i in permutations(S,len(S))]
lis = sorted(list(set(lis)))

print(lis[K-1])
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