• programming language/python
[파이썬 실력 테스트] 20. 사전식 정렬 출력
oujin
2022. 8. 18. 17:59
728x90
●문제: 임의의 단어의 끝자리 부터 한글자씩 늘려서 출력하면서 사전식으로 정렬하여 출력하시오
입력 예시: apple
출력 예시:
apple
e
le
ple
pple
방법 1
def solve(s) :
result = []
last = len(s)
for i in range(1, len(s)+1) :
result.append(s[last-i:])
result.sort()
return result
s = input()
for j in solve(s):
print (j)
방법 2
s = input()
temp=[]
for i in range(len(s)) :
temp.append(s[-(i+1):])
a = sorted(temp)
for j in a:
print (j)
출력
apple
apple
e
le
ple
pple
출처: 예제 중심 파이썬 입문
궁금한 부분이 있으면 댓글 부탁드립니다^^
728x90