c# - Regarding program that calculates time through keypad -


a mobile phone has 12 keys input, (‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘0’, ‘*’ , ‘#’).

in standard text input mode each key can used input letters of alphabet , space character. example, access letter ‘b’ user press ‘2’ key twice.

it takes user minimum of 100 ms press key. if user has use same key input consecutive characters there must @ least 0.5 second pause phone accept next key press represents new character.

i want write console application accepts string can entered using key assignments in grid using c#. application should accept input user , calculate minimum time required user input string using key pad , sequence of keys required.

if know can me write program.

this should give idea:

class mobilegrid {     const int min_duration = 100;     const int wait_duration = 500;      private static dictionary<char, tuple<char, int>> grid;     static mobilegrid()     {         grid = new dictionary<char, tuple<char, int>>();         grid.add('a', tuple.create('2', 1));         grid.add('b', tuple.create('2', 2));         grid.add('c', tuple.create('2', 3));         grid.add('d', tuple.create('3', 1));         grid.add('e', tuple.create('3', 2));         grid.add('f', tuple.create('3', 3));         grid.add('g', tuple.create('4', 1));         grid.add('h', tuple.create('4', 2));         grid.add('i', tuple.create('4', 3));         grid.add('j', tuple.create('5', 1));         grid.add('k', tuple.create('5', 2));         grid.add('l', tuple.create('5', 3));         grid.add('m', tuple.create('6', 1));         grid.add('n', tuple.create('6', 2));         grid.add('o', tuple.create('6', 3));         grid.add('p', tuple.create('7', 1));         grid.add('q', tuple.create('7', 2));         grid.add('r', tuple.create('7', 3));         grid.add('s', tuple.create('7', 4));         grid.add('t', tuple.create('8', 1));         grid.add('u', tuple.create('8', 2));         grid.add('v', tuple.create('8', 3));         grid.add('w', tuple.create('9', 1));         grid.add('x', tuple.create('9', 2));         grid.add('y', tuple.create('9', 3));         grid.add('z', tuple.create('9', 4));     }      public static int calculateminimumtime(string word)     {         int totalmillis = 0;         (int index = 0; index < word.length; index++)         {             tuple<char, int> charinfo = grid[word[index]];             int pos = charinfo.item2;             int clicktime = pos * min_duration;             if (index != 0)             {                 tuple<char, int> lastcharinfo = grid[word[index - 1]];                 if (lastcharinfo.item1 == charinfo.item1)                     clicktime += wait_duration;             }             totalmillis += clicktime;         }         return totalmillis;     } } 

then you'd total minimum required time:

int totalmillis = mobilegrid.calculateminimumtime("hello"); //1800 

note: have add special chars white-space.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -