OperateString
SRM 779 · 2020-02-20 · by lazy_fox
Problem Statement
You have a string. Initially, this string is s.
You are going to perform a sequence of operations on this string. Each operation has an integer argument X. The operation is performed as follows:
- If X is positive, X times take the first character of the string and move it to the end of the string.
- If X is negative, -X times take the last character of the string and move it to the beginning of the string.
- If X is zero, nothing happens.
You are given the initial string s and the
Constraints
- s will have between 1 and 1000 characters, inclusive.
- Each character of s will be a lowercase English letter ('a'-'z').
- moves will have between 1 and 100 elements, inclusive.
- Each element of moves will be between -10^9 and 10^9, inclusive.
"abcde"
{3}
Returns: "deabc"
When applying the operation, we move the 'a' to the end (producing "bcdea"), then we move the 'b' to the end (producing "cdeab"), and finally we move the 'c' to the end, producing the final output: "deabc".
"abcde"
{1,2}
Returns: "deabc"
After the first operation (with argument 1) we have "bcdea", after the second operation (with argument 2) we have "deabc".
"abracadabra"
{-3}
Returns: "braabracada"
"topcoder"
{-5,7,-2,13}
Returns: "dertopco"
"topcoder" -> "codertop" -> "pcoderto" -> "topcoder" -> "dertopco".
"havefunsolvingthissrmwatchoutfortimeoutsmakesureyoursolutionisfastenough"
{1000000000,-900000000,800000000,-700000000,600000000,543210987}
Returns: "ingthissrmwatchoutfortimeoutsmakesureyoursolutionisfastenoughhavefunsolv"
Have fun solving this SRM! Watch out for timeouts, make sure your solution is fast enough.
Submissions are judged against all 29 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class OperateString with a public method string operate(string s, vector<int> moves) · 29 test cases · 2 s / 256 MB per case