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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Zip function in Python to change to a new character set
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Find a string such that every character is lexicographically greater than its immediate next character
- Replace every character of string by character whose ASCII value is K times more than it
- Replace every character of a string by a different character
- Map every character of one string to another such that all occurrences are mapped to the same character
- Modify the string such that every character gets replaced with the next character in the keyboard
- Replace all occurrences of character X with character Y in given string
- Create a new string by alternately combining the characters of two halves of the string in reverse
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Longest Common Prefix using Character by Character Matching
- Count substrings that starts with character X and ends with character Y
- Shortest distance to every other character from given character
- Nearest smaller character to a character K from a Sorted Array
- Remove new lines from string in PHP
- 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.
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- 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
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.