Found 7346 Articles for C++

C++ Program to find number of calling person pairs are calling

Arnab Chakraborty
Updated on 07-Apr-2022 10:36:59

131 Views

Suppose we have an array A with n elements. A[i] determines the ith id. A[i] is the number of SKP call session. If A[i] is 0, it indicates the person is not using SKP calling system. We have to analyze these data and find out the number of pairs of calling person that are talking. If this is not possible, return -1.Problem CategoryThis problem falls under sorting problems. Sorting is a very common problem while we are talking about different problem-solving algorithms in computer science. As the name suggests, sorting indicates arranging a set of data into some fashion. We ... Read More

C++ Program to find tram lines we are in in different trips

Arnab Chakraborty
Updated on 07-Apr-2022 10:31:03

180 Views

Suppose we have a nested list with n sub-lists L. There are several stops on a tram track. Among them only n stops we have seen. L[i] contains another list and the size of L[i] list determines the number of tram lines on that stop. The values of L[i] list is line numbers, and they can be in arbitrary order. We have to find what are the possible lines of the tram we were in?Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we have to devise an algorithm first and to do that ... Read More

C++ Program to find out if a person has won lottery

Arnab Chakraborty
Updated on 07-Apr-2022 10:23:07

889 Views

Suppose, there is a jackpot lottery going on where there are 100 tickets, each ticket numbered within a number from 1 to 100. Now, the lottery company has decided only the player with ticket number 20 will win the jackpot prize, and ticket holders of number 11 to 21 will win a consolation prize each. So, we have to design the software for that. Given the ticket number, we have to print any one of these three messages, "Sorry, you have lost.", "You have won the jackpot!!!", and "You have won the consolation prize." The ticket number is supplied by ... Read More

C++ Program to find out the total price

Arnab Chakraborty
Updated on 07-Apr-2022 10:20:47

2K+ Views

Suppose, we have gone to a shop to buy three items. We have to buy two items of each kind. We have to buy items of prices b and d, but there is a choice between buying items of prices a and c. We buy the lowest priced item between a and c. Find out the total of the items we have purchased, an extra amount of 2 is added to the total for tax purposes. Multiply it by two, and print the total price.Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we ... Read More

C++ Program to find out the health of a character

Arnab Chakraborty
Updated on 07-Apr-2022 10:18:20

235 Views

Suppose, we are playing a 2d scrolling game. The character of the game is currently located in position pos with health h. When the character proceeds in the game, he gains pos amount of health, and the pos value decreases in each step. Whenever the character encounters an obstacle at position oh or ph, the character's health decreases by od or pd respectively. The character stops moving only when he is in pos 0. We have to find out the health h of the character in position pos = 0.Problem CategoryVarious problems in programming can be solved through different techniques. ... Read More

C++ Program to find and replace in a string

Arnab Chakraborty
Updated on 07-Apr-2022 09:17:35

830 Views

Suppose, we are given a string s. There is a range, from start to end where start and end are both integers. Whenever we encounter the character stored in variable f within the given range, we replace it with the character stored in r. We find out the string after this replacement operation.Problem CategoryTo solve this problem, we need to manipulate strings. Strings in a programming language are a stream of characters that are stored in a particular array-like data type. Several languages specify strings as a specific data type (eg. Java, C++, Python); and several other languages specify strings ... Read More

C++ Program to find out if there is a pattern in a grid

Arnab Chakraborty
Updated on 07-Apr-2022 09:12:43

258 Views

Suppose, we are given a grid of dimensions n * n. We have to detect if there is a cross pattern in the grid, like below −#...# .#.#. ..#.. .#.#. #...#The grid can only contain '#' and '.'. We have to detect the pattern and find out how many such patterns are in the grid. The grid and the dimension are given to us as input.Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we have to devise an algorithm first, and to do that we have to study the particular problem in detail. ... Read More

C++ Program to find out the number of border cells in a grid

Arnab Chakraborty
Updated on 07-Apr-2022 09:06:35

287 Views

Suppose, we are given a grid of dimensions h * w. We have to color the border cells of the grid (i.e. the outermost cells of the grid) with a special color. We have to find out how many border cells we have to color.Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we have to devise an algorithm first, and to do that we have to study the particular problem in detail. A recursive approach can be used if there is a recurring appearance of the same problem over and over again; alternatively, ... Read More

C++ Program to find number of working components

Arnab Chakraborty
Updated on 07-Apr-2022 09:04:23

154 Views

Suppose, there is an electronic control board that implies the status of all the components in a system. Each component status is depicted using two LEDs; if any one of them is lit then that component is working. In the board, there are n rows of LED lights, and m components status are in a particular row; that means there are 2*m LED lights in each row. A given array 'grid' depicts the status of the board, if a light is lit then it is '1', otherwise '0'. We have to find out the number of components currently working from ... Read More

C++ Program to print unique integer pairs

Arnab Chakraborty
Updated on 07-Apr-2022 08:57:46

240 Views

Suppose, we are given two arrays a and b that each contain n integer numbers. From the arrays, we have to create integer pairs where one number is from array a and another one is from array b, and the addition of the numbers is always unique. We print all such integer pairs.Problem CategoryThe above-mentioned problem can be solved by applying Greedy problem-solving techniques. The greedy algorithm techniques are types of algorithms where the current best solution is chosen instead of going through all possible solutions. Greedy algorithm techniques are also used to solve optimization problems, like its bigger brother ... Read More

Advertisements