Fun with string.

3.7

10 votes
Problem

Xavier challenges one of his friend to perform some crazy string functions by giving him some words and each word basically denotes a type of string function which his friend has to perform.

WORDS WITH THEIR MEANING:-

Wordrev n->To arrange each words of the string in reverse order.The last letter n denotes upto which letter the words are to be reversed in the string. For example:-the given string is my name is xavier,the given task is Wordrev 3.Then the output must be ym eman si xavier.The 3 words are reversed because the last letter is 3 that is the task is performed for 3 words,and the remaining are simply dispalyed same as they were.

subpalin n->To find the nth palindrome substring present in the given string.Here n denotes the nth palindrome substring. For eg the string is xyzbabmadamh,the task is subpalin 2.The output must be madam which is the substring of given input string."ababa" is also a palin substring but it is not the second,it was the first substring.

sortword n->To sort the given string words alphabetically.The letter n denotes the step upto which the sorting is to be done.For example:-The string is he loves to play cricket and the given task is sortword 2.Then the output would be "cricket he to play loves" only the first two words are sorted rest remainsunsorted

Xaviers friend plans to write a program to solve these questions easily.

Input FORMAT

The first line inputs the String on which the task is to be performed. Next line denotes number of test cases T. The next line inputs the T NUMBER tasks to be performed one by one.

Output Format

The output string after the application of each function one by one.

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?