Found 7347 Articles for C++

Printing Different pattern Bash in C++

Ajay yadav
Updated on 16-Jan-2020 12:20:09

251 Views

This article is intended to print a half-pyramid pattern bash using the C++ programming language. In the view of the stipulated pattern to be printed, the following algorithm is being orchestrated to achieve our goal as;AlgorithmStep-1 Set the length of the Bash (Height) Step-2 Outer loop to handle the number of rows Step-3 Inner loop to handle columns Step-4 Print the pattern with the character (@) Step-5 Set the pointer to a new line after each row (outside the inner loop) Step-6 Repeat the loop till the Bash HeightExampleSo, the following C++ source code is ultimately carved out by complying ... Read More

Printing Interesting pattern in C++

Ajay yadav
Updated on 16-Jan-2020 12:18:55

209 Views

This article prints an interesting pattern using C++ programming. Here is the algorithm as followingAlgorithmStep-1 Define the size which will be double automatically Step-2 Print the upper section using a loop Step-3 Print the lower section using a loopExampleBased on the above algorithm, the following c++ code is carved out as; Live Demo#include using namespace std; int main(){    int n=3;    int i,j;    // This is upper half of pattern    for (i=1; i

Printing Pyramid using Recursion in C++

Ajay yadav
Updated on 16-Jan-2020 12:18:13

774 Views

This article aims to print a pyramid pattern by using the recursive implementation of C++ programming. Here is the algorithm as following to do so;AlgorithmStep-1 Set the height of the pyramid Step-2 Adjust space using recursion function Step-3 Adjust Hash(#) character using recursion function Step-4 Call both functions altogether to print the Pyramid patternExampleAs said the above algorithm, the following genuine C++ code economics is written as following; Live Demo#include using namespace std; // function to print spaces void print_space(int space){    if (space == 0)       return;    cout

Proj() function for Complex Numbers in C++

Ajay yadav
Updated on 16-Jan-2020 12:14:34

103 Views

This article demonstrate the functioning of proj() in order to perform projection upon complex numbers. Here the syntax of the proj() method in c++ programming as follows;template complex proj (const complex& z);ExampleThe proj() method takes a parameter as argument which represent the complex number and returns the projection of complex number described below in the sample as; Live Demo#include #include using namespace std; int main(){    std::complex c1(3, 5);    cout

Two City Scheduling in C++

Arnab Chakraborty
Updated on 28-Apr-2020 17:33:00

388 Views

Suppose there are 2N persons. A company wants to organize one interview. The cost for flying the i-th person to city A is costs[i][0], and the cost for flying the i-th person to city B is costs[i][1]. We have to find the minimum cost to fly every person to a city, such that N people arrive in every city. So if the given list is [[10, 20], [30, 200], [400, 50], [30, 20]] The output will be 110. So we will send the person P1 to city A with cost 10, Second person to city A with cost 30, third ... Read More

Long Pressed Name in C++

Arnab Chakraborty
Updated on 28-Apr-2020 17:17:37

235 Views

Suppose a man is typing some name on keyboard. Sometimes some buttons are long-pressed by mistake. So it may type one or more extra character. So we will take two strings, and check whether the second string is long-pressed name or not. So if the name is “Amit”, and second string is “Ammittt” is longpressed name. But “Ammttt” is not, because character i is not present here.To solve this, we will follow these steps −let j := 0for i := 0, i < second.size, increase i by 1 −if j < actual_name.size and actual_name[j] = second[i], thenincrease j by 1return ... Read More

Letter Case Permutation in C++

Arnab Chakraborty
Updated on 28-Apr-2020 16:50:02

216 Views

Suppose we have a string with letters and numbers. We have to generate all possible combinations of that string by taking uppercase and lowercase versions of letters that are present in the string. So if one string has only numbers, only that will be returned. Suppose the string is like “1ab2”, then the strings will be [“1ab2”, “1Ab2”, “1aB2”, “1AB2”]To solve this problem, we will use recursive approach. It takes the index parameter to start work from that index. It also takes a temp string up to which the result is created. When the index is same as the string ... Read More

Repeated Substring Pattern in C++

Arnab Chakraborty
Updated on 28-Apr-2020 16:38:05

1K+ Views

Suppose we have a non-empty string. We have to check whether it can be constructed by taking a substring of it and appending multiple times of the substring. The string consists of lowercase English letters only and its length will not exceed 10000. So if the input is like “abaabaaba”, then answer will be true, as this is created using “aba”To solve this, we will follow these steps −We will use the dynamic programming approach.Define an array DP of size n. n is the size of the stringi := 1 and j := 0while i < nif str[i] == str[j], ... Read More

Find All Numbers Disappeared in an Array in C++

Arnab Chakraborty
Updated on 28-Apr-2020 16:34:03

360 Views

Suppose we have an array of n elements. Some elements appear twice and other appear once. Elements are in range 1 0, then add i + 1 into the answerreturn the answerExampleLet us see the following implementation to get better understanding − Live Demo#include using namespace std; void print_vector(vector v){    cout

Convert given string so that it holds only distinct characters in C++

Ayush Gupta
Updated on 16-Jan-2020 07:36:25

179 Views

In this tutorial, we will be discussing a program to convert given string so that it holds only distinct characters.For this we will be provided with a string. Our task is to traverse through the string and replace all the recurring characters with any random characters that are not already present into the string.Example Live Demo#include using namespace std; //collecting the distinct characters //in the string int calculate_zero(int i, int occurrences[]){    while (i < 26) {       //if it is present only once       if (occurrences[i] == 0)          return i;     ... Read More

Advertisements