Convert Sentence to Mobile Numeric Keypad Sequence in C++

Ayush Gupta
Updated on 06-Jan-2020 12:02:35

723 Views

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 Live Demo#include 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

Convert a Number of Length n with One Digit at Least k Times in C++

Ayush Gupta
Updated on 06-Jan-2020 11:57:57

131 Views

In this tutorial, we will be discussing a program to convert a number of length N such that it contains any one digit at least ‘K’ times.For this we will be provided with a number of given length N. Our task is to convert the digits in the given number such that any one digit gets repeated at least ‘K’ times. Also, you have to calculate the cost of this operation which is the absolute difference between the two and finally print the minimum cost.Example Live Demo#include using namespace std; //calculating the minimum value and final number int get_final(int n, ... Read More

Convert Number M to N Using Minimum Operations in C++

Ayush Gupta
Updated on 06-Jan-2020 11:44:39

810 Views

In this tutorial, we will be discussing a program to convert a number m to n using minimum number of given operations.For this we will be provided with two integers m and n. Our task is to convert the integer m to n using the given operations least times.Allowed operations −Multiply the given number by 2Subtract one from the given numberExample Live Demo#include using namespace std; //finding minimum number of operations required int convert(int m, int n){    if (m == n)       return 0;    if (m > n)    return m - n;    //can't convert ... Read More

Convert a Number into Negative Base Representation in C++

Ayush Gupta
Updated on 06-Jan-2020 11:40:34

307 Views

In this tutorial, we will be discussing a program to convert a number into its negative base representation.For this we will be provided with a number and the corresponding negative base. Our task is to convert the given number into its negative base equivalent. We are allowing only values between -2 and -10 for negative base values.Example Live Demo#include using namespace std; //converting integer into string string convert_str(int n){    string str;    stringstream ss;    ss > str;    return str; } //converting n to negative base string convert_nb(int n, int negBase){    //negative base equivalent for zero is ... Read More

Convert Normal BST to Balanced BST in C++

Ayush Gupta
Updated on 06-Jan-2020 11:35:35

242 Views

In this tutorial, we will be discussing a program to convert a normal binary search tree to balanced binary search tree.For this we will be provided with a skewed binary search tree either left or right. Our task is to convert it into a balanced binary search tree following a certain set of rules.Example Live Demo#include using namespace std; //node structure of tree struct Node{    int data;    Node* left, *right; }; //traversing tree and storing node pointers //in vector nodes void store_nodes(Node* root, vector &nodes){    if (root==NULL)       return;    store_nodes(root->left, nodes);    nodes.push_back(root);   ... Read More

Convert Binary Tree to Doubly Linked List in C++ - Set 2

Ayush Gupta
Updated on 06-Jan-2020 11:31:18

173 Views

In this tutorial, we will be discussing a program to convert a binary tree to a doubly linked list.For this we will be provided with a binary tree. Our task is to convert it into a doubly linked list such that the left and right pointers become the previous and next pointers. Also the sequential order of the doubly linked list must be equal to the inorder traversal of the binary tree.For this we are having a different approach. We will be traversing the binary tree in reverse inorder way. Along with we will be creating new nodes and moving ... Read More

Convert Binary Tree to Doubly Linked List in C++ - Set 1

Ayush Gupta
Updated on 06-Jan-2020 11:22:03

238 Views

In this tutorial, we will be discussing a program to convert a binary tree to a doubly linked list.For this we will be provided with a binary tree. Our task is to convert it into a doubly linked list such that the left and right pointers become the previous and next pointers. Also the sequential order of the doubly linked list must be equal to the inorder traversal of the binary tree.For this we are having a very straight forward approach. We will be traversing the binary tree in in order way making the nodes of the doubly linked list ... Read More

Convert Binary Tree to Logical and Property Tree in C++

Ayush Gupta
Updated on 06-Jan-2020 11:16:54

164 Views

In this tutorial, we will be discussing a program to convert a given Binary tree to a tree that holds Logical AND property.For this we will be provided with a binary tree. Our task is to convert it into a tree that holds the logical AND property means that a node has a value of the AND operation of its children nodes. Note that every node can have a value either zero or one.Example Live Demo#include using namespace std; //node structure of binary tree struct Node{    int data;    struct Node* left;    struct Node* right; }; //creation of a ... Read More

Understanding CSS Units

AmitDiwan
Updated on 06-Jan-2020 10:53:39

125 Views

CSS Units come in a variety of categories such as font-sizes, character-sizes, viewport dimensions, etc. Broadly there are two categories of absolute and relative units which consist of above mentioned sub categories.Following are the CSS absolute units −Sr.NoUnit & Name1cmCentimeters (1 cm = 100 mm)2inInches (1 in = 2.54 cm)3mmMillimeters4pcPicas (1 pc = 12 pt)5ptPoints (1 pt = 1/72 in)6pxPixels (1 px = 0.75 pt)Let us see an example of CSS absolute units −Example Live Demo CSS Absolute Units form {    width:70%;    margin: 0 auto;    text-align: center; } * {    padding: 2px;    margin:5px; ... Read More

Setting Line Height in CSS

AmitDiwan
Updated on 06-Jan-2020 10:37:33

80 Views

The height of a line can be defined by the CSS line-height property. It accepts only positive values.SyntaxThe syntax of CSS line-height property is as follows −Selector {    line-height: /*value*/ }ExampleThe following examples illustrate the CSS line-height property. Live Demo div * {    margin: 1.5em;    box-shadow: -13px -10px 10px 1px crimson; } #demo {    line-height: 60%; } p {    box-shadow: 13px -10px 10px 1px grey;    line-height: 50px; } Demo Heading This is demo text one. This is demo text two. This is demo text three. OutputThis ... Read More

Advertisements