String Manipulations


Submit solution

Points: 20
Time limit: 8000.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C++, Python

This is a simple data structures problem. Your task is to perform set of the operations (Reverse/PalindromeChecking/LeftCircularShift) over the given string.

Input:
  • The first line of input is the maximum size of the stack (N)
  • The second line of the input is the inputstring (S)
  • The third line of input is number of operations (M)
  • Following M lines will include series of operations of the following type

      R-reverse 
      P-PalindromeChecking
      S-Left Circular Shift

    The first operation is over the input string given by the user. If an operation Y(R/P/S) is followed by an another operation X (R/P/S), the operation Y should be carried out over the resultant string of operation X i.e, the output string from one operation will be input to next operation.

    For example,

      if P(PalindromeChecking) is followed by R(reverse) then, P(PalindromeChecking) should be over reversed string which is produced by R(reverse).
    
      If  P(PalindromeChecking) is followed by S(Left Circular Shift) then, P(PalindromeChecking) should be over the string produced by S(Left Circular Shift). 
    
      Since P-PalindromeChecking doesnot change the string, input string of any operation  X will be same as the input string P
    
      If R is followed by R, then second R operation is over the resultant of first R operation. For example, input string is "abcd" then after first R output is dcba. after the second R, output is abcd.
Output:

Output of each operation will be in newline.

  • Output of R (Reverse) is reversed string of input string. If "abc" is the input string, then output is "cba"

  • Output of P(PalindromeChecking) is True or False. If "aba" is the input string, then output is True

  • Output of S(Left Circular Shift), the ouptut is left shifted string. If "abcd" , then output is "bcda"

Sample Input:

10 abcdabc 6 P R S R P R

Sample Output:

False

cbadcba

badcbac

cabcdab

False

badcbac

Explanation:

input string "abcdabc"

P - since it is the first operation palindrome check over the input string . hence, result is False

R-Reverse the string - it will over the string after Palindrome check and the output is "cbadcba"

S-Left cirucular Shift - it will take "cbadcba" and produce "badcbac"

R-Reverse - It will take "badcbac" and produce "cabcdab"

PalindromeChecking - check over "cabcdab" and hence output is False

R-Reverse - It will take "cabcdab" and produce "badcdbac"


Comments