题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
while True: try: s = input() mark = [[], []] # 记录特殊符号、空格、数字的原本位置 s0 = '' # 只记录字母 for i in range(len(s)): if s[i].isalpha(): s0 = s0 + s[i] else: mark[0].append(s[i]) mark[1].append(i) s1 = sorted(s0, key=str.upper) for i in range(len(mark[0])): s1.insert(mark[1][i], mark[0][i]) print(''.join(s1)) except: break