Do you know you can earn heaps of $$ by answering questions on kodlogs, for more info contact us through feedback link at footer? We are Australian based web site and pay you for answering questions

  • Register
Welcome to Kodlogs Q&A, where you can ask programming questions and receive answers from other members of the community. For programmers, by programmers Kodlogs is an open community for anyone that does coding. We help you get answers to your toughest coding questions, share knowledge with your coworkers in private, and find your next IT dream job.
0 votes
3 views
How do i convert a sentence into its equivalent mobile numeric keypad sequence? Any c# code example ?
by (930 points)  

2 Answers

0 votes
Given a sentence as a string, convert it into its proportional versatile numeric keypad grouping.

Pursue the means offered underneath to change over a sentence into its identical portable numeric keypad succession.

For each character, store the succession which ought to be gotten at its separate position in an exhibit, for example for Z, store 9999. For Y, store 999. For K, store 55, etc.

For each character, subtract ASCII estimation of 'An' and acquire the situation in the cluster pointed

by that character and include the succession put away in that cluster to a string.

In the event that the character is a space, store 0

Print the general grouping.

/C++ execution to change over a

/sentence into its comparable

/portable numeric keypad succession

#include <bits/stdc++.h>

utilizing namespace std;

/Function which registers the succession

string printSequence(string arr[],

string input)

{

string yield = "";

/length of info string

int n = input.length();

for (int i=0; i<n; i++)

{

/Checking for space

on the off chance that (input[i] == ' ')

yield = yield + "0";

else

{

/Calculating record for each

/character

int position = input[i]-'A';

yield = yield + arr[position];

}

}

/Output arrangement

return yield;

}

/Driver work

int principle()

{

/putting away the arrangement in cluster

string str[] = {"2","22","222",

"3","33","333",

"4","44","444",

"5","55","555",

"6","66","666",

"7","77","777","7777",

"8","88","888",

"9","99","999","9999"

};

string input = "KODSSFORKOODS";

cout << printSequence(str, input);

return 0;

}

Yield :

433335577773336667774333355777
by (930 points)  
0 votes

CONVERT THE SENTENCE INTO ITS EQUIVALENT MOBILE NUMERIC KEYPAD SEQUENCE

 

Before new smart phones in olden days the phones were utilized for making calls to family and friends. These days’ smart phones are like supercomputers.

To convert a string into its equivalent mobile numeric keypad sequence, we take a string as input and store the equivalent keypad sequence of each letter in an array i.e., for A we store 2 (as in old mobile phones we have letter A on the numeric 2 and we press it once to get letter A) for B we store 22 (we press the numeric 2 twice to get the letter B)in the same way we find the numeric sequence for each letter and store it in a string.

 

PROBLEM STATEMENT:

 

Given a sentence in the form of a string, convert it into its equivalent mobile numeric keypad sequence.

 

EXAMPLES:

 

INPUT: HELLO WORLD

 

OUTPUT: 443355555666096667775553

 

INPUT: BEAUTIFUL

OUTPUT: 2233288844433388555

 

For obtaining a number, we need to press a number corresponding to that character for number of times equal to position of the character.

 

Eg: for character C we press number 2 three times and accordingly

 

Steps to convert a sentence into its equivalent mobile numeric keypad sequence:

 

For each character, store the sequence which should be obtained at its respective position in an array i.e., for Z, store 9999,for k store 55

For each character, subtract ASCII value of ‘A’ and obtain the position in the array pointed by the character and add the sequence stored in that array to a string.

If the character is a space, store 0.

Print the overall sequence.

 

 ALGORITHM:

 

//INPUT: String

 

//OUTPUT: Displays an equivalent mobile numeric keypad sequence.

 

    //str is used to store the sequence in an array

 

//outputstring is used to store the overall sequence

 

//inputstring is used to store the string given

 

//length stores the length of the inputstring

 

Step1: Start

 

//storing the sequence in an array

 

Step 2:Initialize str={“2”,”22”,”222,”3”,”33”,”333”,”4”,”44”,”444”,”5”,”55”,”555”,”6”,”66”,”666”,”7”,”77”,”777”,”7777”,”8”,”88”,”888”,”9”,”99,”999”“9999”}

 

Step3: Read inputstring

 

Step4: n=length of inputstring

 

Step5: for i=0 to n do

 

//check if the character is a space, add 0 to the output

 

                         if (inputstring[i]==’ ‘ then

 

                                   outputstring= outputstring+”0”

 

                         endif

 

                         else

 

// if the character is not a a space calculate index for each character by subtracting the character by A and add the sequence stored in that index to the output

 

                                   index=inputstring[i]-“A”

 

                                   outputstring= outputstring+str [index]

 

                         endelse

 

endfor

 

Step6: Display outputstring

 

Step 7: Stop

by (930 points)  
...