#45062: 非常直觀的解法 Python


s210367@student.cysh.cy.edu.tw (張少謙)

學校 : 國立嘉義高級中學
編號 : 263937
來源 : [36.232.110.106]
最後登入時間 :
2025-01-02 21:22:02
q182. 2. 字串操作 -- 2025年1月APCS | From: [36.232.119.129] | 發表日期 : 2025-01-05 20:26

def change(s):
  for i in range(len(s)//2):
    s[i*2], s[(i*2)+1] = s[(i*2)+1], s[i*2]
  return s

def twosort(s):
  name = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
  for i in range(len(s)//2):
    if name.index(s[i*2]) > name.index(s[(i*2)+1]):
      s[i*2], s[(i*2)+1] = s[(i*2)+1], s[i*2]
  return s

def wash(s):
  a = s[0:(len(s)//2)]
  b = s[(len(s)//2):len(s)]
  c=[]
  for i in range(len(s)//2):
    c.append(a[i])
    c.append(b[i])
  return c

s = list(input())
k = int(input())
for i in range(k):
  a = int(input())
  if a == 0:
    s = change(s)
  elif a == 1:
    s = twosort(s)
  elif a == 2:
    s = wash(s)

for j in s:
  print(j, end="")
 
ZeroJudge Forum