AMSCO1 - 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:

4 1 3 2 5
IN C OM P LE
T EC O LU M
NA R WI T HA
L TE R NA T
IN G SI N GL
E LE T TE R
SA N DD I GR
A PH S    

 

 

 

 

 

 

 

 

 

Input

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

Output

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

Example

Input:

41325 INCOMPLETECOLUMNARWITHALTERNATINGSINGLELETTERSANDDIGRAPHS Output:

 CECRTEGLENPHPLUTNANTEIOMOWIRSITDDSINTNALINESAALEMHATGLRGR

Added by:legrand
Date:2013-02-28
Time limit:0.108s-1s
Source limit:5000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ADA95 GAWK BASH C C++ 4.3.2 CPP C99 FORTRAN GO HASK JAVA OCAML PAS-GPC PAS-FPC PERL PIKE PYTHON PYTHON3 PY_NBC RUBY
Resource:classical ciphers

hide comments
2013-08-15 20:54:52 cho cho
i am always getting wrong answer ... please check my submission id=9846963
=>I see you have it AC now.

Last edit: 2013-08-18 09:38:45
2013-06-29 19:19:09 shiv prasad chabarval
@legrand please check my code and tell me where it fails id:9575315
=>same problem in your bad outputs
thnx legrand got it :)

Last edit: 2013-06-30 17:38:54
2013-06-27 07:06:05 SWOOSH!!!
Please give a test case for which my solution fails... Submission ID 9325790
=>there are \0 inside your bad outputs

Last edit: 2013-06-30 08:15:04
2013-06-24 17:38:23 Ouditchya Sinha
@legrand : Thank you for pointing out my mistake, now I can try AMSCO2. This problem was making the interpretation of AMSCO2 difficult. :)
2013-06-21 13:06:10 Ouditchya Sinha
Good Question! :)
@Rudiger: My AC solution for your testcase 21 ABCDEF gives CFABDE following this scheme -
AB C
DE F
=>the right scheme is Rudiger's one. your solution for this testcase is wrong, but it's not in the testcases.

Last edit: 2013-06-22 14:49:53
2013-06-05 07:51:05 Tywan
Why not open to Ruby and other languages?
=>It's now open to Ruby and more.

Last edit: 2013-06-05 09:36:58
2013-06-05 07:51:05 Atul Kumar Verma
What is the output for
12 ABCD
=> it's ABDC

Last edit: 2013-05-19 15:26:14
2013-06-05 07:51:05 daft_wullie
What is the scheme for even column numbers? e.g. for 21 ABCDEF:
AB C
D EF?
--edit: it is (if it is a testcase). Got AC with this concept.

Last edit: 2013-04-09 21:25:37
2013-06-05 07:51:05 Man Mohan Mishra
@legrand: please check , why i am getting wrong answer .....
: ok , found my mistake. AC :)
nice problem !!

Last edit: 2013-03-12 18:25:44
2013-06-05 07:51:05 Thotsaphon Thanatipanonda
Open Java please
=>legrand: That's done.
@legrand: Thankssssssss

Last edit: 2013-03-09 02:57:48
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.