Statistics

Problem Statement for "PoemCode"

Problem Statement

PROBLEM STATEMENT

In his book "Between Silk and Cyanide," Leo Marks recounts his experiences as
the man in charge of British spy codes during World War II.  When he first came
to the position in 1941, he was dismayed to find that agents were using an
insecure and error-prone code which was based on poems.

As the first step in encoding a message using the poem code, an agent would
select several words from a poem and form a transposition key from these words,
as detailed below.  A subsequent procedure used the transposition key to
scramble the message plaintext into encrypted ciphertext.  Unfortunately,
agents in the field were under severe pressure and time constraints, and
frequently made errors when creating the transposition key.  This had the
effect of making the encoded messages created using these erroneous keys
indecipherable by the home office.  Any indecipherable message had to be
re-encoded and resent by the agent, at great risk; Germans used
direction-finding vehicles to home in on the source of radio transmission
signals.

Your task is to write a function which would have been a great asset to the
agents had it been available 60 years ago.  This function must create the
correct transposition key from the input text.  

To create a transposition key from text, take the first letter in the alphabet
that appears in the text.  Number each occurrence of this letter in the text
from left to right, starting with 1, 2, 3, etc.  Ignore case.  Then take the
next letter in the alphabet that appears in the text and again number each
occurrence of this letter from left to right, continuing the numbering from
where you previously left off.  Continue until done.  The following example
illustrates:

Quoth the raven, Nevermore.

The first letter in the alphabet which appears in this text is a.  Thus:

                            1
 Q  U  O  T  H  T  H  E  R  A  V  E  N  N  E  V  E  R  M  O  R  E

The next letter that appears is e.  Numbering the e's, we get:

                      2     1     3        4     5              6
 Q  U  O  T  H  T  H  E  R  A  V  E  N  N  E  V  E  R  M  O  R  E

Next comes h:

             7     8  2     1     3        4     5              6
 Q  U  O  T  H  T  H  E  R  A  V  E  N  N  E  V  E  R  M  O  R  E

Continuing through the last letter, v, gives the finished key:

14 20 12 18  7 19  8  2 15  1 21  3 10 11  4 22  5 16  9 13 17  6
 Q  U  O  T  H  T  H  E  R  A  V  E  N  N  E  V  E  R  M  O  R  E

Your function should return the numbers across the top.

DEFINITION

Class:  PoemCode
Method name:  makeKey
Parameters:  String
Returns:  int[]
Method signature (be sure your method is public):  int[] makeKey(String text)

NOTES

TopCoder will ensure that the input string:
- Will have a length from 0 to 50 characters, inclusive.
- Will contain only letters, spaces, commas, and periods.

If there is no usable text in the input string, return an empty transposition
key.

EXAMPLES

makeKey("Quoth the raven, Nevermore.") =
{14,20,12,18,7,19,8,2,15,1,21,3,10,11,4,22,5,16,9,13,17,6}
makeKey("Alas.  Poor Yorick.") = {1,6,2,13,10,7,8,11,14,9,12,4,3,5}
makeKey("ZZTopCoder") = {9,10,8,4,6,1,5,2,3,7}

Definition

Class:
PoemCode
Method:
makeKey
Parameters:
String
Returns:
int[]
Method signature:
int[] makeKey(String param0)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: