PROBLEM STATEMENT
Children sometimes pick an item from a group of items by using a rhyme or other
phrase. They do this by assigning each word in the phrase to an item, starting
with the first item and moving one-by-one to the last item in order, then
starting again with the first item if there are still more words in the phrase
once the last item is reached. Whichever item they end up assigning the last
word of the phrase to is picked.
Create a class Eenie with a method meenie which, when given a String phrase
that contains a phrase, and an int numitems which represents the total number
of items to pick from, returns the number of the item picked using the
described method with the input phrase.
DEFINITION
Class: Eenie
Method: meenie
Parameters: String, int
Returns: int
Method signature (be sure your method is public): int meenie(String phrase,
int numitems);
NOTES
- A word is defined here as a continuous string of letters (including 'A'-'Z'
and 'a'-'z') containing no spaces - separated by spaces, or the beginning or
end of the input String.
- The item number returned should be between 1 (representing the first item)
and numitems (representing the last item), inclusive.
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following criteria are met:
- String phrase will consist of only letters ('A'-'Z' and 'a'-'z') and spaces
(' ').
- String phrase will be between 1 and 50 letters in length, inclusive.
- String phrase will not contain two spaces in a row.
- String phrase will neither start nor end with a space.
- int numitems will be between 1 and 100, inclusive.
EXAMPLES
In each of these examples, quotes ('"') are included for clarity only. They
are never part of the input or output.
Example #1:
phrase = "Eenie Meenie Miney Mo"
numitems = 3
return: 1
You will assign the word "Eenie" to item #1, then "Meenie" to item #2, then
"Miney" to item #3 then finally "Mo" (the last word) to item #1.
Example #2:
phrase = "Catcha tiger byits toe"
numitems = 3
return: 1
Example #3:
phrase = "Hi"
numitems = 3
return: 1
Example #4:
phrase = "One Two Three"
numitems = 9
return: 3
Example #5:
phrase = "One Two Three"
numitems = 1
return: 1
Example #6:
phrase = "A B C D E F G H I J K"
numitems = 3
return: 2