TopcoderArchiveVisit Topcoder
SRM8 Mar 2002
SRM 71

WordSize

Problem statement, definition, constraints, and public examples.

Problem Statement

PROBLEM STATEMENT

Class name: WordSize
Method name: numletters
Parameters: String
Returns: int[]

The method signature is (make sure it is declared public):
int[] numletters(String input);

input is a String of words separated by exactly one space

Given a String input, you are to determine how many words within the String
have 1, 2, 3, ..., 9, or 10 letters.

Always return an int[] of size 10. Arrange these quantities into an int[], such
that element 0 of the return int[] contains the number of words of length 1,
and element 1 contains the number of words of length 2, etc.

TopCoder will enforce the following restrictions:
* input will be between 1 and 50 characters in length, inclusive.
* input will contain only letters (A-Z, a-z) and spaces.
* no word in input will be longer than 10 letters.
* there will be exactly one space between words in input.
* input will have no leading or trailing spaces.

Examples:
"this is a test" contains 1 word of length 1, 1 word of length 2, 0 words of
length 3,
and 2 words of length 4. The return value is {1, 1, 0, 2, 0, 0, 0, 0, 0, 0}.

"Hello world a to two four three eighth seventh" contains:
1 word of length 1
1 word of length 2
1 word of length 3
1 word of length 4
3 words of length 5
1 word of length 6
1 word of length 7
The return value is {1, 1, 1, 1, 3, 1, 1, 0, 0, 0}

"the quick brown fox jumped over the lazy gray dogs" returns:
{0, 0, 3, 4, 2, 1, 0, 0, 0, 0}

"What is this world coming to" returns:
{0, 2, 0, 2, 1, 1, 0, 0, 0, 0}

Definition

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

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems