Help Sherlock Holmes
All submissions for this problem are available.
It’s a lovely morning in London. In 221B Baker Street, Sherlock Holmes is figuring out how to send the message to his friend Dr. Watson so that nobody else can understand.
The English text he wants to hide or encrypt is done using following method:
Step 1: Remove all the spaces present in the message (sentence) and let LEN be its length.
Step 2: The characters are carefully written in a matrix whose rows and columns have the following constraint: Floor(√LEN) <= ROW <= COLUMN <= Ceil(√LEN)
For example, let the input be:
the dark con of the man
Removing the space, the sentence becomes:
and its LEN: 18.
So, the matrix will have Floor (√18) rows and Ceil (√18) columns. That is Rows: 4 and Columns: 5 and the characters are written as:
To ensure 1: rows X columns >= LEN (In our example: 4 X 5 >= 18)
To ensure 2: If multiple matrices satisfy the above conditions, choose the one with the minimum area, i.e. minimum rows X columns.
The encrypted sentence (message) is obtained by combining all the characters in a column, then inserting a space, and then repeating the same for all the columns.
For example, the encoded message for the above input is:
trom hkfa ectn doh ane
The maximum sentence length is 81 characters. Lets help The Sherlock Holmes.
- One like consisting the input sentence OR English Text.
- Output a single line containing English text helping Sherlock form the Encrypted Message.
Input: have a nice day Output hae and via ecy
Input: feed the dog Output fto ehg ee dd
|Time Limit:||4 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions