Thief of Wealth
시간 제한메모리 제한제출정답맞은 사람정답 비율
1 초256 MB21331348122364.915%

문제

Saruman the White and his underling, Grima Wormtongue, communicate with each other using a secret code, a language as twisted as their hearts. However, the Rangers are very clever, and they realize that reversing each message will reveal their adversary’s plotting. Aragorn has tasked you with decoding an archive of their messages.

Given a message on each line, output the decoded message.

입력

A series of encrpyted messages, one per line. A line with the 3-character string ”END” will indicate the end of input; this line should not be decoded, and should not generate any output.

출력

The list of decrypted messages, one per line.


이 문제는 그냥 입력에 END가 나오기전까지의 문자열을

한줄씩 뒤집어서 출력해주면 된다.

난이도는 최하.


그럼 python에서는 어떻게 문자열을 뒤집는가?

1. "문자열"[::-1]

:: 모든 구간을 -1 간격으로 슬라이스 하겠다는 표현이다. 즉 거꾸로 표현하겠다는 뜻.

2. reversed()

reversed("문자열") 을 하면 문자열이 뒤집어 진다.

허나, print( reversed("문자열") ) 을 하면 reversed객체의 메모리 주소값이 나오는데

이를 string 형으로 바꿔주려면 str()이 아닌 join()을 써줘야 한다.  "".join(list객체) 는 list객체를 str형으로 바꾸는 것과 같다.

"".join( reversed("문자열") )


아래는 완성 코드

texts = input()

while texts != "END":

    print( "".join(reversed(texts)) )

    texts = input()


'개발 > 알고리즘' 카테고리의 다른 글

15652 N과 M(4)  (0) 2019.01.05
15651 N과 M(3) 중복순열  (0) 2019.01.05
15650 N과 M(2) feat.오름차순 순열  (0) 2019.01.05
15649 N과 M(1)  (0) 2019.01.05
1476 날짜계산  (0) 2019.01.04
profile on loading

Loading...