Modify the string such that every character gets replaced with the next character in the keyboard | C ++ implementation of the approach ; Function to return the modified string ; Map to store the next character on the keyboard for every possible lowercase character ; Update the string ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; const string CHARS = " qwertyuiopasdfghjklzxcvbnm " ; const int MAX = 26 ; string getString ( string str , int n ) { unordered_map < char , char > uMap ; for ( int i = 0 ; i < MAX ; i ++ ) { uMap [ CHARS [ i ] ] = CHARS [ ( i + 1 ) % MAX ] ; } for ( int i = 0 ; i < n ; i ++ ) { str [ i ] = uMap [ str [ i ] ] ; } return str ; } int main ( ) { string str = " geeks " ; int n = str . length ( ) ; cout << getString ( str , n ) ; return 0 ; }