Mirror characters of a string | 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 ; Creating a string having reversed alphabetical order ; The string up to the point specified in the question , the string remains unchanged and from the point up to the length of the string , we reverse the alphabetical order ; Driver function
#include <iostream> NEW_LINE #include <string> NEW_LINE using namespace std ; string compute ( string str , int n ) { string reverseAlphabet = " zyxwvutsrqponmlkjihgfedcba " ; int l = str . length ( ) ; for ( int i = n ; i < l ; i ++ ) str [ i ] = reverseAlphabet [ str [ i ] - ' a ' ] ; return str ; } int main ( ) { string str = " pneumonia " ; int n = 4 ; string answer = compute ( str , n - 1 ) ; cout << answer ; return 0 ; }