+ 1

Which algorithm is best for converter of symbols?

For example, I have string (symbols): "Privet", and I want change it to UPNBFL. How to I can do it? By array or any other way? P=>u, r=>p, I=>n, etc.

22nd Oct 2017, 7:48 PM
Юname Ъ
2 odpowiedzi
0
There are a few things you can try. You could create a HashMap, with the key being the original letter, and the value being the translated letter (I.e. The key would be the letter "p", and the value be "u"). If you do not have any knowledge on this data structure, I will be happy to explain it to you. Another option you have is to compare between two strings. For example, say, you have the original alphabet, "abc...xyz", and then a String containing what each letter corresponds to, where the first letter of the original String corresponds to the first letter of the translated, the second letter of the original to the second of the translated, and so on. Find the index of the letter you wish to translate in the original String, then take the letter at the index in the translated String. You can also try "hard-coding" it, where you have an if-then statement for every possible character translation. I wouldn't recommend this strategy, though. It isn't adaptable.
22nd Oct 2017, 10:01 PM
Quantallax
+ 1
@Quantallax there's an easy way that you can just make an array of 26 chars. Just like this: https://code.sololearn.com/c4R3r444kY9S/?ref=app
23rd Oct 2017, 1:17 AM
Chriptus13
Chriptus13 - avatar