Rotate String

0

0 votes
Problem

You are given a string and a number of queries to perform. For each query you have to rotate the string either left or right. For example, if the string is abcde, rotating left by 1 character will give bcdea. Now rotating again right by 1 character will give abcde back.

Find the resultant string after performing all the queries.

Input Fomat

  • The first line of input contains N denoting the size of the string.
  • The second contains the string of size N
  • Third  line contains Q denoting the number of queries. Each of the next Q lines contains one query.
  • Each query consists of a single character which can either be l or followed by a number k. If the character is l, then you have to rotate the string left by k characters, and if it is r, then you have to rotate the string right by k characters.

Output Format

  • Print the resultant string after performing all the queries.

Constraints

  • 1N,Q,k106

Author: Ankit Saini

Sample Input
5
abcde
3
l 1
l 1
r 1
Sample Output
bcdea
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The input string is abcde

After the first query:  bcdea

After the second query: cdeab

After the third query: bcdea

Editor Image

?