Given a string and a number N, we need to mirror the characters from N-th position up to the length of the string in the alphabetical order. In mirror operation, we change ‘a’ to ‘z’, ‘b’ to ‘y’, and so on.
Input : N = 3
Output : paizwlc
We mirror characters from position 3 to end.
Input : N = 6
Output : pnefnlmrz
Mirroring the alphabetical order means that a corresponds to z, b corresponds to y. Which means that first character becomes the last and so on. Now, to achieve this we maintain a string(or a character array) which contains the English alphabets in lower case. Now from the pivot point up to the length, we can look up the reverse alphabetical order of a character by using its ASCII value as an index. Using the above technique, we transform the given string in the required one.
// C++ code to find the reverse alphabetical
// order from a given position
// Function which take the given string
// and the position from which the reversing shall
// be done and returns the modified string
string compute(string str, intn)
// Creating a string having reversed alphabetical order
Please Login to comment...