Problem Statement
PROBLEM STATEMENT
You are an archeologist who is working on piecing together a dictionary of
words that existed in some extinct language. All you have to work with is a
simple short story in that language, but you feel this story contains a
reasonably complete set of vocabulary for this language. You now want to write
software that can retrieve words from this set of vocabulary in a reliable
manner.
You decide you want to represent this language's vocabulary the same way we
represent English - with a dictionary. You plan to extract each unique word
and sort it (case insensitively - meaning capital letters are considered
equivalent to their lower-case counterparts) into a list of unique words.
However, you realize that this dead language does not use the same order of the
alphabet that we do in English - though, fortunately, it does use the same 26
letters.
Create a class DeadLang that contains a method dictEntry which takes a single
integer argument "index" which represents the index of the word to be retrieved
from this "dictionary" where 1 is the first word, a single string "alpha" which
represents the ordering of the letters in this dead language - exactly 26
capital letters with no repetitions, and a list of strings "story", which
represent the text of the story you have, and returns the word (in all capital
letters) at position "index" in the dictionary formed by case-insensitively
sorting all words in these stories using this language's alphabetical order and
removing duplicates (also case insensitively).
DEFINITION
Class: DeadLang
Method: dictEntry
Parameters: int, String, String[]
Returns: String
Method signature (be sure your method is public): String dictEntry(int index,
String alpha, String[] story);
NOTES
- These stories may contain numbers, punctuation, spaces, etc... but you are
only concerned with words (contiguous groups of capital and lower-case letters).
- Non-letter characters (characters other than 'a'-'z' and 'A'-'Z', inclusive)
terminate words - as do the ends of a strings in story.
- There may be multiple non-letter characters in a row. These do not comprise
a word.
- For example, the line: "how43do4you4 23 DO" represents four words: "how",
"do", "you" and "DO". Note that "do" and "DO" represent the SAME word, so only
3 different words would be added to the dictionary from this line.
- An index value of 1 (not 0) represents the first word.
- The word returned should be in all capital letters.
- When ordering words, a word that is completely identical to the beginning of
another word comes before that other word. For example: "CAT" comes
alphabetically before "CATCH" - no matter the alphabet's order.
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following criteria are met:
- story will contain between 1 and 50 strings, inclusive.
- Each string in story will be between 1 and 50 characters in length, inclusive.
- Each string in story will contain only the characters 'a'-'z', 'A'-'Z',
'0'-'9', comma (','), period('.'), and space (' ') - all ranges inclusive.
- String alpha will be of length 26 with each of the capital letters ('A'
through 'Z', inclusive) listed exactly once.
- Words in story will be no longer than 9 letters each.
- index will be between 1 and the number of words in story (inclusive).
EXAMPLES
In each of these examples, quotes ('"'), commas (','), curly braces ('{' and
'}'), and parenthesis ('(' and ')') are included for clarity only. They are
never part of the example input or output.
Example #1)
index = 4
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
story = {"Three... two... one... Liftoff.", "Shuttle Discovery has lifted off."}
return "LIFTOFF"
The sorted dictionary will contain the words in this order: DISCOVERY, HAS,
LIFTED, LIFTOFF, OFF, ONE, SHUTTLE, THREE, TWO. The fourth word (which was the
one requested) is "LIFTOFF".
Example #2)
index = 9
alpha = "ZYXWVUTSRQPONMLKJIHGFEDCBA"
story = {"This is a lengthy story. It keeps", "Going and going...."}
return "AND"
The sorted dictionary will contain the words in this order: THIS, STORY,
LENGTHY, KEEPS, IT, IS, GOING, A, AND.
Example #3)
index = 8
alpha = "QWERTYUIOPASDFGHJKLZXCVBNM"
story = {"This is a lengthy story. It keeps", "Going and going...."}
return "KEEPS"
The sorted dictionary will contain the words in this order: THIS, IT, IS, A,
AND, STORY, GOING, KEEPS, LENGTHY.
Example #4)
index = 3
alpha = "QWERTYUIOPASDFGHJKLZXCVBNM"
story = {"Three... two... one... Liftoff.", "Shuttle Discovery has lifted off."}
return "OFF"
Definition
- Class:
- DeadLang
- Method:
- dictEntry
- Parameters:
- int, String, String[]
- Returns:
- String
- Method signature:
- String dictEntry(int param0, String param1, String[] param2)
- (be sure your method is public)
Constraints
Examples
No public sample cases were explicitly marked for this problem in the original data.