题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#进行了深拷贝 import sys import copy lines=sys.stdin.readlines() l=list(lines[0]) fz=[] for i in range(len(l)): if l[i].isalpha(): fz.append(l[i]) l[i]="pending" old=copy.deepcopy(fz) # print(old) for i in range(len(fz)): for j in range(i+1,len(fz)): if fz[i].upper()>fz[j].upper() : fz[i],fz[j]=fz[j],fz[i] for item in fz: for i in range(len(l)): if l[i]=='pending': l[i]=item break for i in range(len(l)): for j in range(len(old)): if l[i].upper()==old[j].upper(): l[i]=old[j] old.remove(old[j]) break result="" for item in l: result=result+item print(result)