#P10058. String Transformation Operations
String Transformation Operations
String Transformation Operations
Given a string (S = s_0 s_1 \cdots s_{k-1}) and (n) operations, perform the operations sequentially to obtain a final string (S').
There are three types of operations:
< x
: Left cyclic rotation by (x) positions. For example, for (\mathtt{abcde}), performing< 2
yields (\mathtt{cdeab}).> x
: Right cyclic rotation by (x) positions. For example, for (\mathtt{abcde}), performing> 2
yields (\mathtt{deabc}).rev
: Reverse the string. For example, for (\mathtt{abcde}), performingrev
yields (\mathtt{edcba}).
Note: For a string (S = s_0 s_1 \cdots s_{k-1}), a left rotation by (x) positions transforms it into (s_{x} s_{x+1} \cdots s_{k-1} s_0 s_1 \cdots s_{x-1}). Similarly, a right rotation by (x) positions transforms it into (s_{k-x} s_{k-x+1} \cdots s_{k-1} s_0 s_1 \cdots s_{k-x-1}). Operations are applied sequentially.
inputFormat
The input consists of multiple lines:
- The first line contains the initial string (S).
- The second line contains an integer (n), the number of operations.
- Each of the following (n) lines contains one operation. An operation is either in the format
< x
or> x
where (x) is an integer, or the stringrev
.
outputFormat
Output the resulting string after performing all (n) operations sequentially.
sample
abcde
3
1
cbaed