Guest User

Untitled

a guest
Jun 27th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import com.uchuhimo.collections.BiMap
  2. import com.uchuhimo.collections.toBiMap
  3.  
  4. val eng = "~!@#$%^&*()QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?`qwertyuiop[]asdfghjkl;'zxcvbnm,./"
  5. val ru = "Ё!\"№;%:?*()ЙЦУКЕНГШЩЗХЪ/ФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,ёйцукенгшщзхъфывапролджэячсмитьбю."
  6.  
  7. val biMap: BiMap<Char, Char> by lazy {
  8. eng.zip(ru).toMap().toBiMap()
  9. }
  10.  
  11. fun engToRus(string: String) = string.map { biMap[it] ?: it }.joinToString("")
  12.  
  13. fun rusToEng(string: String): String {
  14. val inv = biMap.inverse
  15. return string.map { inv[it] ?: it }.joinToString("")
  16. }
Add Comment
Please, Sign In to add comment