Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- /*
- |-----------------------|
- | 1 | 2 | 3 |
- | .,?! | abc | def |
- |-----------------------|
- | 4 | 5 | 6 |
- | ghi | jkl | mno |
- |-----------------------|
- | 7 | 8 | 9 |
- | pqrs | tuv | wxyz |
- |-----------------------|
- | * | 0 | # |
- | '-+= | ⎵ | case |
- |-----------------------|
- */
- public class Program
- {
- public static string strjoin( char[] x )
- {
- string j = "";
- foreach ( var o in x )
- {
- j += o.ToString();
- }
- return j + '\0';
- }
- public static int is_all_caps( string x )
- {
- var upper = strjoin(
- ( from z in x.Trim()
- where Char.IsUpper( z )
- select z )
- .ToList()
- .ToArray() );
- return upper.Length ^ x.Length;
- }
- public static string to_t9( string val )
- {
- var asdf = new( string, string )[]
- { ( "1", "./,/?/!" ),
- ( "2", "a/b/c" ),
- ( "3", "d/e/f" ),
- ( "4", "g/h/i" ),
- ( "5", "j/k/l" ),
- ( "6", "m/n/o" ),
- ( "7", "p/q/r/s" ),
- ( "8", "t/u/v" ),
- ( "9", "w/x/y/z" ),
- ( "*", "'/-/+/=" ) };
- int upper = is_all_caps( val );
- if ( val.Length < 1 )
- {
- return val;
- }
- if ( val.Length == 1 )
- {
- return Char.IsUpper( val[0] ) ? "# " + val : val;
- }
- if ( upper != 0 )
- {
- string v = "";
- foreach ( char x in val )
- {
- if ( x == ' ' )
- {
- v += "0 ";
- continue;
- }
- if ( Char.IsUpper( x ) )
- {
- v += "# ";
- }
- foreach ( ( string k, string p ) in asdf )
- {
- if ( p.Contains( Char.ToLower( x ) ) )
- {
- string[] qwerty = p.Split( '/' ).Where( e => e != "/" ).ToArray();
- int times = 1;
- foreach ( string q in qwerty )
- {
- if ( q == Char.ToLower( x ).ToString() )
- {
- break;
- }
- else
- {
- times += 1;
- }
- }
- v += new String( k[0], times );
- v += " ";
- }
- }
- }
- return v;
- }
- else
- {
- string v = "## ";
- foreach ( char x in val )
- {
- if ( x == ' ' )
- {
- v += "0 ";
- continue;
- }
- foreach ( ( string k, string p ) in asdf )
- {
- if ( p.Contains( Char.ToLower( x ) ) )
- {
- string[] qwerty = p.Split( '/' ).Where( e => e != "/" ).ToArray();
- int times = 1;
- foreach ( string q in qwerty )
- {
- if ( q == Char.ToLower( x ).ToString() )
- {
- break;
- }
- else
- {
- times += 1;
- }
- }
- v += new String( k[0], times );
- v += " ";
- }
- }
- }
- return v;
- }
- }
- public static void Main()
- {
- var asdf = new string[]
- {
- "GENERATING TEST CASES",
- "=====================",
- " Hello World = " + to_t9( "Hello World" ),
- " HELLO WORLD = " + to_t9( "HELLO WORLD" ),
- " abba feed high = " + to_t9( "abba feed high" ),
- " I love PHP = " + to_t9( "I love PHP" ),
- " there r 4 lights! = " + to_t9( "there r 4 lights!" )
- };
- foreach ( string line in asdf )
- {
- Console.WriteLine( line );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment