Koala - 5기/기초 알고리즘 스터디

[백준/python] - 5363번: 요다

알 수 없는 사용자 2022. 1. 24. 00:02

문제

https://www.acmicpc.net/problem/5363

풀이

join 과 indexing 을 활용하여 깔끔하게 한줄로 리스트를 문자열로 구성했다. 먼저 문장의 개수를 입력받고 문장을 받을 때마다 split 하여 단어단위로 저장했다. 이를 join 을 사용해서 뒤의 “두번째 단어 부터 마지막 단어까지”, “앞에서 두개의 단어” 로 각각의 문자열로 바꿔준 뒤에 합쳐서 출력했다.

코드

count = int(input())
words = []

for i in range(count) :
    word = input().split()
    words.append(word)

for i in range(count) :
    print(" ".join(words[i][2:len(words[i])]) +" "+ " ".join(words[i][0:2]))