Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
C++ Articles
Page 546 of 597
Converting one string to other using append and delete last operations in C++
In this tutorial, we will be discussing a program to convert one string to other using append and delete last operations.For this we will be provided with two strings. Our task is to calculate whether the first string can be converted into the second one by performing k operations of append and delete last element.Example#include using namespace std; //checking if conversion between strings is possible bool if_convert(string str1, string str2, int k){ if ((str1.length() + str2.length()) < k) return true; //finding common length of both string int commonLength = 0; for (int i = ...
Read MoreElse and Switch Statements with initializers in C++17
In many cases, we need to verify the value of something returned by a function and perform conditional operations based on this value. So our code is given below −// Some method or function return_type foo(Params) // Call function with Params and // store return in var1 auto var1 = foo(Params); if (var1 == /* some value */) { //Perform Something } else { //Perform Something else }Just follow the general format in all conditional if-else blocks. Firstly there is exist an optional initial statement which sets up the variable, followed by the if-else block. So the general ...
Read More2-Satisfiability(2-SAT) Problem in C/C++?
Let f = (x1 ∨ y1) ∧ (x2 ∨ y2) ∧ ... ∧ (xn ∨ yn).Problem: Is f satisfiable?xi ∨ yi and and are all equivalent. So we are converting each of (xi ∨ yi) s into those two statements.Now assume a graph with 2n vertices. In case of each of (xi∨yi) s two directed edges are addedFrom ¬xi to yiFrom ¬yi to xif is not treated as satisfiable if both ¬xi and xi are in the same SCC (Strongly Connected Component)Assume that f is treated as satisfiable. Now we want to provide values to each variable in order to satisfy ...
Read MorePrint all nodes that are at distance k from a leaf node in C++
In this problem, we are given a binary tree and a number K. We have to print all nodes of the tree that are at k distance from the leaf node.Binary Tree is a special tree whose each node has at max two nodes (one/two/none).The leaf node of a binary tree is the node at end of the tree.In this problem, distance from the leaf node is the node at a higher level than the leaf node. Suppose, the node at distance 2 from the leaf node at level 4 will be at level 2.Let’s take an example to understand ...
Read MoreConvert given time into words in C++
In this tutorial, we will be discussing a program to convert given time into words. For this we will be provided with a specific time in the digital format.Our task is to convert that particular time into wordsExample#include using namespace std; //printing time in words void convert_time(int h, int m){ char nums[][64] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "twenty one", ...
Read MoreHow to install Doxygen on Ubuntu
Doxygen is the de facto regular tool for generating documentation from annotated C++ sources, however, it additionally supports different wellknown programming languages akin to C, objective-C, C#, Hypertext Preprocessor, Java, Python, IDL (Corba, Microsoft, and UNO/OpenOffice flavors), Fortran, VHDL and Tcl. This article explains about-“how to install Doxygen on Ubuntu”To install Doxygen, use the following command –$ sudo apt-get install doxygenThe sample output should be like this –Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libterm-readkey-perl linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic linux-signed-image-4.4.0-31-generic Use 'sudo ...
Read MoreElements present in first array and not in second using STL in C++
We have two arrays, the task is to compare the two arrays and find the numbers present in first array but not in the second array, using Standard Template Library (STL) in C++.ExampleInput: array1[ ] = {1, 2, 3, 4, 5, 7} array2[ ] = {2, 3, 4, 5, 6, 8} Output: 1, 7 Input: array1[ ] = {1, 20, 33, 45, 67} array2[ ] = {1, 12, 13, 114, 15, 13} Output: 20, 33, 45, 67Approach used in the below program is as follows −In this program we want to find the elements which are present in the first ...
Read MorePrint all sequences starting with n and consecutive difference limited to k in C++
In this problem, we are given three variables n, s, and k and we have to print all the possible sequences that start with the number n and length s having the absolute difference between consecutive elements less than k. Let's take an example to understand the topic better − Input: n = 3, s = 3 , k = 2 Output: 3 3 3 3 3 4 3 3 2 3 4 4 3 4 5 3 4 3 3 2 2 3 2 3 3 2 1 In this problem, we need to obtain the ...
Read MorePrint all subsequences of a string using ArrayList in C++
In this problem, we are given a string and we have to print all subsequences of the string. The substring is formed by deleting elements. Also, the order of string should not be altered.Let’s take an example to understand the problem better −Input: string = “xyz” Output: x y xy z xz yz xyzTo solve this problem, we will find all substring starting from freezing the first character of the string and find subsequence accordingly, then going for the next character in string and subsequence.Examplepublic class Main { public static void printSubString(String sub, String subSeq){ if ...
Read MorePrint all subsequences of a string in C++
In this problem, we are given a string and we have to print all the subsequences of the string. The substring generated is created by deleting the elements of the string but the order remains the same(i.e. Order cannot be changed).Let’s take an example to understand the topic better −Input: xyz Output: x, y, z, xy, yz, xz, xyzExplanation − In the above example, we can see the only characters are deleted to create substring. No, rearranging takes place.There can be multiple methods to solve this problem, here we will discuss a few of them to understand methods.One is by ...
Read More