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
- 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
- Find a string such that every character is lexicographically greater than its immediate next character
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Replace all occurrences of character X with character Y in given 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 the given string according to the given conditions
- Change gender of a given string
- How to Append a Character to a String in C
- How to remove the first character of string in PHP?
- Kth most frequent Character in a given String
- Replace a character c1 with c2 and c2 with c1 in a string S
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.