[Python] 알고리즘/Silver
[6616] 문자열 암호화 (Python)
-Becca-
2021. 11. 29. 11:55
[문제]
https://www.acmicpc.net/problem/6616
6616번: 문자열 암호화
남들이 멋대로 정보를 읽을 수 없도록 하기 위하여, 많은 사람들은 암호화 알고리즘을 이용해 암호화를 하게 됩니다. 이런 암호화 방법을 사용하여 평문(message)를 암호문(ciphertext)로 바꾸게 되
www.acmicpc.net
알고리즘 분류는 구현, 문자열 입니다.
2
ABCDEFGH
결과 : AEBFCGDH
[코드]
import sys
while True:
N = int(sys.stdin.readline())
if N == 0:
break
text = "".join(sys.stdin.readline().rstrip().split()).upper()
dt = dict()
i = 0
m = 0
cnt = 0
while True:
if len(dt) == len(text):
break
if i >= len(text):
cnt += 1
i = cnt
dt[i] = text[m]
i += N
m += 1
dt = sorted(dt.items(), key=lambda x: x[0])
for i in dt:
print(i[1], end="")
print()