Change string to a new character set | CPP program to change the sentence with virtual dictionary ; Converts str to given character set ; hashing for new character set ; conversion of new character set ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void conversion ( char charSet [ ] , string & str ) { int n = str . length ( ) ; char hashChar [ 26 ] ; for ( int i = 0 ; i < 27 ; i ++ ) hashChar [ charSet [ i ] - ' a ' ] = ' a ' + i ; for ( int i = 0 ; i < n ; i ++ ) str [ i ] = hashChar [ str [ i ] - ' a ' ] ; } int main ( ) { char charSet [ 27 ] = " qwertyuiopasdfghjklzxcvbnm " ; string str = " egrt " ; conversion ( charSet , str ) ; cout << str ; return 0 ; }