AMSCO2 - Decipher the AMSCO cipher

Here you have to decipher the AMSCO cipher:

Due to A.M.SCOtt in the 19th century, it's an incomplete columnar transposition cipher with alternating single letters and digraphs. The first entry must be a digraph. In both even and odd periods the first column and the first row always alternate:

7 4 5 6 3 2 1
RI D ER S ON T HE
S TO R MI N TO T
HI S HO U SE W EA
R EB O RN J IM M
OR R IS O N

Input

N lines (N < 1000) Each line of the input contains the numeric key (permutation order of the columns) and a ciphertext. Ciphertext letters are in [A-Z] only with no punctuation. The keylength max is 9 and the length of the ciphertext is limited to 250. The last line ends with EOF.

Output

Output consist of exactly N lines of plaintexts with letters in [A-Z] with no spaces.

Example

Input:
7456321 HETEAMTTOWIMONNSEJNDTOSEBRERRHOOISSMIURNORISHIROR

Output:
RIDERSONTHESTORMINTOTHISHOUSEWEAREBORNJIMMORRISON
Input:
41325 CECRTEGLENPHPLUTNANTEIOMOWIRSITDDSINTNALINESAALEMHATGLRGR

Output:
INCOMPLETECOLUMNARWITHALTERNATINGSINGLELETTERSANDDIGRAPHS

Added by:legrand
Date:2013-04-04
Time limit:0.100s
Source limit:10000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ADA95 GAWK BASH C C++ 4.3.2 CPP C99 LISP sbcl LISP clisp FORTRAN GO HASK JAVA LUA OCAML PAS-GPC PAS-FPC PERL PHP PIKE PYTHON PYTHON3 PY_NBC RUBY SCM guile SCM qobi
Resource:classical ciphers

hide comments
2017-11-10 04:55:00
Reused AMSCO1 code in a really dumb way. Not too proud of this AC..
Edit: Having failed to debug an optimized solution, I concede that the dumb way was the correct approach ;)

Last edit: 2017-11-10 07:33:43
2016-03-31 20:52:45
doing AMSCO1 before this makes it a cakewalk.
2015-12-28 16:18:41 Daksh
just add 10 lines in AMSCO1 :D :)
2014-12-13 09:02:53 Nandu
AC in 1st go...:)


Last edit: 2014-12-14 01:32:47
2014-12-07 10:26:32 ROHIT RAJ
finally AC... feels great
2014-12-03 18:40:12 Diksha Jaiswal
1 WA cos of differences in compilers like ideone n d one used for judging in spoj...feels grt to see green light :D
2014-03-28 08:46:21 Jumpy
nice problem damn happy now
2013-07-03 04:48:55 shiv prasad chabarval
got AC in 1st go :)
2013-06-30 19:13:50 Saurabh Jain
@legrand: I am getting WA again n again even though I verified my solution with a lot of test cases generated using amsco1 code. Can you please give me a hint for the occurrence of same?
=> 30% wrong testcases
@legrand: Thanks .. Got AC :)

Last edit: 2013-07-08 06:55:51
2013-06-10 18:54:57 Utsav Sinha
@legrand: please check my code, id - 9455124, it works for the test cases and many cases produced from AMSCO1, but gives wrong answer. thanks in advance...
=>verify the length of your answers: at the end of all your wrong outputs there are 2 or 3 '\0' and sometimes an extra alpha char before the '\n'

@legrand: Thanks !! AC :)

Last edit: 2013-06-12 15:27:15
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.