using System;
public class Test
{
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 } ;
public static int GetKey( char c) {
c = Char.ToLower ( c) ;
if ( c < 'a' )
{
return c == ' ' ? 0 : 1 ;
}
if ( c > 'z' )
{
return 1 ;
}
return KEYS[ c - 'a' ] ;
}
public static void Main( )
{
var testVal = "This is a test!" ;
for ( int i = 0 ; i < testVal.Length ; i++ )
{
Console.WriteLine ( "{0} is key {1}" , testVal[ i] , GetKey( testVal[ i] ) ) ;
}
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJCglwcml2YXRlIHN0YXRpYyBpbnRbXSBLRVlTID0gbmV3IGludFtdezIsMiwyLDMsMywzLDQsNCw0LDUsNSw1LDYsNiw2LDcsNyw3LDcsOCw4LDgsOSw5LDksOX07CgkKCXB1YmxpYyBzdGF0aWMgaW50IEdldEtleShjaGFyIGMpIHsKCQljID0gQ2hhci5Ub0xvd2VyKGMpOwoJCWlmIChjIDwgJ2EnKQoJCXsKCQkJcmV0dXJuIGMgPT0gJyAnID8gMCA6IDE7CgkJfQoJCWlmIChjID4gJ3onKQoJCXsKCQkJcmV0dXJuIDE7CgkJfQoJCXJldHVybiBLRVlTW2MgLSAnYSddOwoJfQoJCglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJdmFyIHRlc3RWYWwgPSAiVGhpcyBpcyBhIHRlc3QhIjsKCQlmb3IgKGludCBpID0gMDsgaSA8IHRlc3RWYWwuTGVuZ3RoOyBpKyspCgkJewoJCQlDb25zb2xlLldyaXRlTGluZSgiezB9IGlzIGtleSB7MX0iLCB0ZXN0VmFsW2ldLCBHZXRLZXkodGVzdFZhbFtpXSkpOwoJCX0KCX0KfQ==