fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5.  
  6. private static int[] KEYS = new int[]{2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
  7.  
  8. public static int GetKey(char c) {
  9. c = Char.ToLower(c);
  10. if (c < 'a')
  11. {
  12. return c == ' ' ? 0 : 1;
  13. }
  14. if (c > 'z')
  15. {
  16. return 1;
  17. }
  18. return KEYS[c - 'a'];
  19. }
  20.  
  21. public static void Main()
  22. {
  23. var testVal = "This is a test!";
  24. for (int i = 0; i < testVal.Length; i++)
  25. {
  26. Console.WriteLine("{0} is key {1}", testVal[i], GetKey(testVal[i]));
  27. }
  28. }
  29. }
Success #stdin #stdout 0.03s 33888KB
stdin
Standard input is empty
stdout
T is key 8
h is key 4
i is key 4
s is key 7
  is key 0
i is key 4
s is key 7
  is key 0
a is key 2
  is key 0
t is key 8
e is key 3
s is key 7
t is key 8
! is key 1