StringMult
SRM 109 · 2002-08-14 · by brett1479
SRM 109 · 2002-08-14 · by brett1479 · String Manipulation
Problem Statement
Problem Statement
The definition of how to multiply a string by an integer follows:
String and an int and return their product.
- The empty string ("") multiplied by any integer is the empty string ("").
For example: "" * 9 = "" - Any string multiplied by 0 is the empty string ("").
For example: "Terrific" * 0 = "" - A non-empty string S multiplied by a positive integer k is the concatenation
of k occurrences of S.
For example: "Great" * 4 = "GreatGreatGreatGreat" - 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"
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
0)
"wOw" 0 Returns: ""
1)
"AbC" -3 Returns: "CbACbACbA"
2)
"Boo" 4 Returns: "BooBooBooBoo"
3)
"" 50 Returns: ""
4)
"Racecar" -5 Returns: "racecaRracecaRracecaRracecaRracecaR"
Submissions are judged against all 29 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class StringMult with a public method string times(string sFactor, int iFactor) · 29 test cases · 2 s / 256 MB per case