Given a 26 letter character set, which is equivalent to character set of English alphabet i.e. (abcd….xyz) and act as a relation. We are also given several sentences and we have to translate them with the help of given new character set.
New character set : qwertyuiopasdfghjklzxcvbnm Input : "utta" Output : geek Input : "egrt" Output : code
Idea behind conversion of new character set is to use hashing. Perform hashing of new character set where element of set is index and its position will be new alphabet value.
Given New character set = “qwertyuiopasdfghjklzxcvbnm”
- First character is q, during hashing we will place ‘a’ (for position ) at index q i.e. (17th).
- After hashing our new character set is “kvmcnophqrszyijadlegwbuft”.
- For input “egrt” =
hash[e -‘a’] = c
hash[g -‘a’] = o
hash[r -‘a’] = d
hash[t -‘a’] = e
For “egrt” is equivalent to “code”.
1.Initialize two strings, one with actual set of alphabets and another with modified one.
2.Get the string to be converted from the user.
3.Retrive the first element of the string, find its index in the modified set of alphabets(eg:0 for ‘q’).
4.Find the element of same index in the actual set of alphabets and concatenate it with the result string.
5.Repeat the above steps for all the remaining elements of the input string.
6.Return the result string.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Zip function in Python to change to a new character set
- Find a string such that every character is lexicographically greater than its immediate next character
- Modify the string such that every character gets replaced with the next character in the keyboard
- Replace every character of string by character whose ASCII value is K times more than it
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Map every character of one string to another such that all occurrences are mapped to the same character
- Replace every character of a string by a different character
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Find the character in first string that is present at minimum index in second string
- Convert the string into palindrome string by changing only one character.
- Queries to find the last non-repeating character in the sub-string of a given string
- Queries to find the first non-repeating character in the sub-string of a string
- Change gender of a given string
- Replace a character c1 with c2 and c2 with c1 in a string S
- Kth most frequent Character in a given String
- How to remove the first character of string in PHP?
- How to Append a Character to a String in C
- Find last index of a character in a string
- Check if both halves of the string have at least one different character
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.