2024年5月23日 星期四

【ZEROJUDGE】e809. 1.字母排序 (Letters)

 e809. 1.字母排序 (Letters)

https://zerojudge.tw/ShowProblem?problemid=e809

解題思路-Python-給我自己的筆記

1。先輸入排序字母排序規則(字串型態s

2。輸入待排序的字串(字串型態d

3。跑迴圈i,跑s。(for i in s)(每次可取出s字串中的某字母)
  利用d.count(i),得知待排序字串d中,s某字母出現的次數
  再利用*出現次數的方法,串接到新字串中。
  t=t+i*(d.count(i))

4。輸入要找幾個字母位置

5。迴圈跑幾次,每次位置值x之後,找到相對應的值串接到答案去

6。再顯示答案就好了

----------------------

程式碼參考

s=input()

d=input()

t=ans=''

for i in s:

    t=t+i*(d.count(i))

n=int(input())

for j in range(n):

    x=int(input())

    ans=ans+t[x-1]+'\n'

print(ans)