Found 7346 Articles for C++

C++ Program to check if a string has been seen before

Arnab Chakraborty
Updated on 07-Apr-2022 08:50:15

119 Views

Suppose, we have n number of strings given to us in an array 'stringArr'. We iterate through the string elements one by one and find out if a string has appeared before in the array. If such occurs, we print 'Seen Before!' or otherwise, we print 'Didn't see before!'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 as a character array ... Read More

C++ Program to find an array satisfying an condition

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

482 Views

Suppose, we are given an array of n integers 'x'. We have to find out another array of integers 'y', so that x[1].y[1] + x[2].y[2] +...+ x[n].y[n] = 0. We print the contents of array y.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, we can use iterative structures also. Control statements such ... Read More

C++ code to find different winner and non-winner counts on a contest

Arnab Chakraborty
Updated on 30-Mar-2022 14:29:04

176 Views

Suppose we have two numbers n and k, There are n students in a contest. Some of them will receive memento, some will get certificates, and others won't receive anything. Who receives something are called winners. But there are some rules of counting the number of memento and certificates. The number of certificates must be exactly k times greater than the number of memento. The number of winners must not be greater than n/2. It's also possible that there are no winners. We have to identify the maximum possible number of winners, according to these rules. Then find the number ... Read More

C++ code to find score of winning square on a square board

Arnab Chakraborty
Updated on 30-Mar-2022 14:29:07

188 Views

Suppose we have a square board of order n x n. Amal and Bimal are playing a game. During the game they write numbers on the board's squares by some unknown rules. Currently the board is showing elements after ending the game. To understand who has won, we need to count the number of winning squares. A particular square is winning we should do the following. Find the sum of all numbers on the squares that share this column and separately calculate the sum of all numbers on the squares that share this row. A square is a winning square ... Read More

C++ code to count maximum banknotes bank can gather

Arnab Chakraborty
Updated on 30-Mar-2022 14:23:19

181 Views

Suppose we have three numbers k, l and m, and have another array A with n elements. A robber failed to rob a bank but had managed to open all the safes of a bank. The blank client decides to take advantage of this failed robbery and steal some money from the safes. In a line there are many safes. There are n banknotes left in all the safes in total. The i-th banknote is in safe A[i]. The bank employee is now at safe k. There are two security guards, one of which guards the safe l such that ... Read More

C++ code to find winner of math contest

Arnab Chakraborty
Updated on 30-Mar-2022 14:19:42

338 Views

Suppose we have two arrays P and T of size n. And have another number c. Amal and Bimal are going to participate one math contest. There are n problems. The ith problem has initial score P[i], and takes T[i] to solve it. P and T both are sorted in increasing order. Here c is the constant for loosing points. If a problem is submitted at time x (x minutes after starting the contest), it gives max(0, P[i] - c*x) points. Amal is going to solve problems in order 1, 2, ... n and Bimal is going to solve them ... Read More

C++ code to count children who will get ball after each throw

Arnab Chakraborty
Updated on 30-Mar-2022 14:16:35

1K+ Views

Suppose we have a number n. Few kids are standing on a circle. They are numbered from 1 to n, they are in clockwise order and the child number 1 is holding the ball. First the child number 1 throws the ball to the next one clockwise, Then the child number 2 throws the ball to the next but one child, (to the child number 4), then the fourth child throws the ball to the child number 7 and so on. When a ball is thrown it may pass the beginning of the circle. Not all the children get the ... Read More

C++ code to find minimum time needed to do all tasks

Arnab Chakraborty
Updated on 30-Mar-2022 14:14:31

382 Views

Suppose we have an array A with n elements, and two other arrays k and x. The ith task takes A[i] time to complete. The given A is sorted in non-decreasing fashion. Amal takes at most k tasks and do each of them in x units of time instead of A[i]. (x < minimum of all A[i]). We have to find the minimum time needed to complete Amal's task. Amal cannot do more than one task simultaneously.So, if the input is like A = [3, 6, 7, 10]; k = 2; x = 2, then the output will be 13, ... Read More

C++ code to count who have declined invitation

Arnab Chakraborty
Updated on 30-Mar-2022 14:11:40

119 Views

Suppose we have an array A with n elements, and all elements are distinct. There are n of the onsite finalists who can join a company, their qualifying ranks are present in array A. We have to find the minimum possible number of contestants that declined the invitation to compete onsite in the final round. There will be 25 person from which, few have accepted or few declined.So, if the input is like A = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28], ... Read More

C++ code to count columns for calendar with month and first day

Arnab Chakraborty
Updated on 30-Mar-2022 14:08:43

260 Views

Suppose we have two numbers m and d. Consider a calendar where week days are represented as columns and rows are current days. We want to know how many columns in the calendar should have given the month m and the weekday of the first date of that month d (Assuming that the year is not leap-year).So, if the input is like m = 11; d = 6, then the output will be 5, because 1-st November is Saturday and 5 columns is enough.StepsTo solve this, we will follow these steps −Define an array a of size: 13 := { ... Read More

Advertisements