
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Convert a sentence into its equivalent mobile numeric keypad sequence in C++
In this tutorial, we will be discussing a program to convert a sentence into its equivalent mobile numeric keypad sequence.
For this we will be provided with a string of alphabetical characters. Our task is to print the numeric equivalent of the string i.e the numerical sequence of the keys to type that particular string.
Example
#include <bits/stdc++.h> using namespace std; //computing the numerical sequence string calc_sequence(string arr[], string input){ string output = ""; //length of input string int n = input.length(); for (int i=0; i<n; i++){ //checking if space is present if (input[i] == ' ') output = output + "0"; else { int position = input[i]-'A'; output = output + arr[position]; } } return output; } int main(){ //storing the sequence in array 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 = "TUTORIALSPOINT"; cout << calc_sequence(str, input); return 0; }
Output
8888666777444255577777666444668
- Related Articles
- Mobile Numeric Keypad Problem\n
- Convert the ASCII value sentence to its equivalent string in C++
- Convert String into Binary Sequence in C++
- Print all n digit patterns formed by mobile Keypad in C++
- Convert a Binary Tree into its Mirror Tree in C++
- How to get all the combinations of the keypad value in a mobile by backtracking using C#?
- How to convert character column of a matrix into numeric in R?
- Split the sentence into words in C++
- Convert the specified string representation of a logical value to its Boolean equivalent in C#
- C# Program to convert first character uppercase in a sentence
- C Program to convert first character uppercase in a sentence
- Convert RE 1(0+1)*0 into equivalent DFA.
- Convert the value of the specified string to its equivalent Unicode character in C#
- Java Program to convert a string into a numeric primitive type using Integer.valueOf()
- How to convert numeric levels of a factor into string in R data frame?

Advertisements