TopcoderArchiveVisit Topcoder
SRM7 Jul 2004
SRM 202

LetterStrings

Problem statement, definition, constraints, and public examples.

Problem Statement

A letter-string is composed of letters ('A'-'Z','a'-'z') and dashes ('-'). The length of a letter-string is the number of characters in it not including dashes (in other words, the number of letters in the string). Given a list of letter-strings you will return the sum of their lengths.

Create a class LetterStrings that contains the method sum, which takes a String[], s, and returns an int representing the sum of the lengths of the given letter-strings.

Definition

Class:
LetterStrings
Method:
sum
Parameters:
String[]
Returns:
int
Method signature:
int sum(String[] s)
(be sure your method is public)

Constraints

  • s will contain between 1 and 50 elements, inclusive.
  • Each element of s will have length between 1 and 50, inclusive.
  • Each element of s will contain only letters ('A'-'Z','a'-'z') and dashes ('-').

Examples

  1. {"-"}
    Returns: 0
  2. {"A"}
    Returns: 1
  3. {"-----Abc"}
    Returns: 3
  4. {"-A-B-C-D", "--------EFGHI", "JKLMNOPQR", "---STU-VW-XYZ"}
    Returns: 26
Back to all problems