TopcoderArchiveVisit Topcoder
SRM16 Jun 2004
SRM 199

StringMult

Problem statement, definition, constraints, and public examples.

Problem Statement

The definition of how to multiply a string by an integer follows:
  1. The empty string ("") multiplied by any integer is the empty string ("").
    For example: "" * 9 = ""
  2. Any string multiplied by 0 is the empty string ("").
    For example: "Terrific" * 0 = ""
  3. A non-empty string S multiplied by a positive integer k is the concatenation of k occurrences of S.
    For example: "Great" * 4 = "GreatGreatGreatGreat"
  4. A non-empty string S multiplied by a negative integer k is the concatenation of k occurrences of the reverse of S.
    For example: "Great" * -4 = "taerGtaerGtaerGtaerG"
Your method will take a String and an int and return their product.

Definition

Class:
StringMult
Method:
times
Parameters:
String, int
Returns:
String
Method signature:
String times(String sFactor, int iFactor)
(be sure your method is public)

Constraints

  • sFactor will have length between 0 and 50 inclusive.
  • iFactor will be between -50 and 50 inclusive.
  • sFactor will contain only letters ('A'-'Z' and 'a'-'z').
  • The length of the returned String (sFactor*iFactor) will be between 0 and 50, inclusive.

Examples

  1. "wOw"
    0
    Returns: ""
  2. "AbC"
    -3
    Returns: "CbACbACbA"
  3. "Boo"
    4
    Returns: "BooBooBooBoo"
  4. ""
    50
    Returns: ""
  5. "Racecar"
    -5
    Returns: "racecaRracecaRracecaRracecaRracecaR"
Back to all problems