The Latin alphabet contains 26 characters and telephones only have ten
digits on the keypad. We would like to make it easier to write a message
to your friend using a sequence of keypresses to indicate the desired
characters. The letters are mapped onto the digits as shown below. To
insert the character
Example
B
for instance, the program would press 22
.
In order to insert two characters in sequence from the same key, the
user must pause before pressing the key a second time. The space
character ' '
should be printed to indicate a pause. For example, 2 2
indicates AA
whereas 22
indicates B
.Example
hi Case #1: 44 444 Follow Up-Now Think if Question asked reverse e.g. Given a telephone number print or produce all the possible telephone words or combinations of letters that can represent the given telephone number, then can you device an algorothm that will solve this problem efficiently. This is More Simple Then Previous One. |
3 comments :
Here is the code :-
space complexity = O(1)
void ConvertToDigit(char input[])
{
int len,i,loop,k,ch,prev;
float digit;
printf("\nEncoded msg\n");
len=strlen(input);
for(i=0;i='t' && input[i]<='u') || input[i]>='w' && input[i]<='x')
{
loop=loop-1;
}
if(prev==digit)
{
printf(" ");
}
for(k=0;k<=loop;k++)
{
printf("%d",(int)digit);
}
}
else
{
printf("0 0");
}
prev=digit;
}
}
ignore above code , its incomplete:-
i dont why its not posting whole code :( :(
Post a Comment