프로그램 명: coci_tajna
제한시간: 1 초
[문제요약]
N 개의 문자를 입력으로 받아 이를 암화화 하여 출력하는 프로그램이다.
암호 알고리즘.
- R 행 C 열의 행렬을 만든다. R <= C 이고 R * C = N 인 행렬을 만든다. 이런 행렬이 여러개인 경우 행이 가장 큰 것을 택한다.
- 이 행렬에 행 우선으로 문자를 채운다.
- 이를 열우선으로 읽는다
예를 들어 koaski 인 6 개의 문자이면
- 2*3 행렬을 만든 후
- 행 우선으로 채운 후(↓)
- 열 우선으로 읽음.(→)
Every evening, little Ivica sends secret messages to little Marica through e-mail. Knowing Ivica's e-letter
travels unguarded through the network on its way to Marica's e-mailbox, they have decided to encrypt
every message using the following algorithm:
-
Suppose Ivica's message consists of N characters.
- Ivica must first find a matrix consisting of R rows and C columns such that R ≤ C and
R·C = N. If there is more than one such matrix, Ivica chooses the one with the most rows.
- Ivica writes his message into the matrix in row-major order. In other words, he writes the first
segment of the message into the first row, the second segment into the second row and so on.
- The message he sends to Marica is the matrix read in column-major order.
Marica has grown tired of spending her precious time deciphering Ivica's messages, so you must write a
program to do it for her.
입력
The input contains the received message, a string of lowercase letters of the English alphabet (with no
spaces).
The number of letters will be between 1 and 100.
출력
Output the original (decrypted) message.
입출력 예
입력
bok
출력
bok
입력
koaski
출력
kakosi
입력
boudonuimilcbsai
출력
bombonisuuladici
Third sample test:
Ivica wants to send the message "bombonisuuladici" containing 16 letters. He can use a 1×16, 2×8 or
4×4 matrix. Of these, the 4×4 has the most rows. When the message is written into it, the matrix looks
like this:
b o m b
o n i s
u u l a
d i c i
출처:coci 2007-2008 contest3 3/6
[질/답]
[제출 현황]
[푼 후(1)]