链接:https://www.nowcoder.com/questionTerminal/7e8aa3f9873046d08899e0b44dac5e43
答案:
# -*- coding:utf-8 -*-
import sys
def yiwei(str):
"""
这个开辟了新空间,不符合题意
"""
xiaoxie = ''
daxie = ''
for i in str:
if i >= 'a' and i <= 'z':
xiaoxie += i
else:
daxie += i
return xiaoxie+daxie
def yiwei2(strs):
"""
基本思路:
将string转化成list,利用列表的pop和append操作实现就地删除和插入
最后用join操作把list转回string
"""
l = list(strs)
index = 0
count = 0
while count < len(strs):
if l[index].isupper():
l.append(l.pop(index))
count += 1
continue
index += 1
count += 1
return ''.join(l)
if __name__ == '__main__':
while True:
line = sys.stdin.readline().strip()
lens = len(line)
if not line:
break
print(yiwei2(line))