Secret Email
InterviewTime limit1sMemory limit128 MB
Given an encrypted string, find matrix dimensions R<=C with R*C=N and largest R, then reverse a row-major-write column-major-read transposition to recover the original message.
- Level
Easy3 of 10
- Topics
- Matrix, String, Implementation
- Solved
- No attempts yet
Problem
Every night, Jungin sends Sanggeun an encrypted email. The original message is a lowercase string of N characters.
Jungin encrypts the message as follows.
- Choose two integers
RandCsuch thatR <= CandR * C = N. If more than one pair is possible, choose the pair with the largestR. - Create a matrix with
Rrows andCcolumns. - Write the original message into the matrix from left to right, starting at the first column of the first row. After a row is full, continue with the next row in the same way.
- Read the matrix column by column. In each column, read from the first row down to the
R-th row to form the encrypted message.
Given the encrypted message that Sanggeun received, restore Jungin's original message.
Input
The first line contains the encrypted message Sanggeun received. The message consists only of lowercase English letters and has length at most 100.
Output
Print the restored original message on the first line.