- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7347 Articles for C++
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
146 Views
A string of 0-9 is given. For this problem, we need to calculate the number of strings that are divisible by 8 and not by 3. This is a 2 step problem, and we need to do the code one step at a time to solve it, for exampleInputstr = "80"Output2Inputstr = "7675636788"Output15Approach to Find the SolutionOnly numbers with their last 3 digits are divisible by 8, and their sum of digits divisible by 3 are divisible by 8.Now store the prefix sum of the string so that the sum of digits of prefix module 3 is either 0, 1, ... Read More
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
239 Views
We'll look at a problem in which we're given an integer string and must determine how many substrings are divisible by 6 in integer format. It should be noted that input is in the form of a String made of numbers (integers). Still, the divisibility check will be performed considering it as an integer only (not using ASCII value of string input).Inputstr = “648”Explanationsubstring “6”, “48”, and “648” are divisible by 6.Inputstr = “38342”Output4Explanationsubstrings “3834”, “342”, ”834”, and “42” are divisible by 6.Brute-Force ApproachUsers can check every possible substring to see if it's divisible by six. If the substring is ... Read More
![Prateek Jangid](https://www.tutorialspoint.com/assets/profiles/399467/profile/60_2793348-1637657587.jpeg)
93 Views
In this tutorial, we have to write an algorithm to find a way to pass an assignment without being caught by the invigilator. Each student has to submit their assignment to the invigilator. Student A's assignment is with Student B, so Student B has to return/pass the assignment to Student A without the invigilator noticing them.All the students are sitting in a queue. We need to find a way to pass the assignment back to Student A without being caught. Various requirements under which they can pass assignments are as follow −Student A (At index i) can pass assignments to ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
133 Views
Suppose we have three numbers n, a and b. We want to buy n liters of water. There are only two types of water bottles nearby, 1-liter bottles and 2-liter bottles. The bottle of the first type a rupees and the bottle of the second type costs b rupees. We want to spend as few money as possible. We have to find the minimum amount of money we need to buy exactly n liters of water.So, if the input is like n = 7; a = 3; b = 2, then the output will be 9, because with 3 2-liter ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
128 Views
Suppose we have an array A with n elements. Consider there are n block towers in a row. The ith tower has height A[i]. In a single day, we can perform the operation: Select two indices i and j (i != j) and move back from tower i to j. It will decrease A[i] by 1 and increase A[j] by 1. The ugliness of the buildings is max(A) − min(A). We have to find the minimum possible ugliness we can achieve.So, if the input is like A = [1, 2, 3, 1, 5], then the output will be 1, because ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
250 Views
Suppose we have a string S with 'L', 'R' and digits from 0 to 9. Consider there is a hotel with 10 rooms they are numbered from 0 to 9, from left to right. The hotel has two entrances-one from the left side, and another from the right side. When a customer arrives to the hotel through the left entrance, they get an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they get an empty room closest to the right entrance. But we have lost the room assignment list. ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
176 Views
Suppose we have two numbers n and k. Amal and Bimal are playing a game. The rules are simple. Amal draws n sticks in a row. After that the players take turns crossing out exactly k sticks from left or right in each turn. Amal starts the game. If there are less than k sticks on the paper before some turn, the game ends. Amal wins if he makes strictly more moves than Bimal. We have to find who will be the winner.So, if the input is like n = 10; k = 4, then the output will be Bimal. ... Read More
C++ Program to count number of operations needed to place elements whose index is smaller than value
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
178 Views
Suppose we have an array A with n elements. We can perform these operations any number of times −Select any positive integer kSelect any position in the sequence and insert k into that positionSo, the sequence is changed, we proceed with this sequence in the next operation.We have to find minimum number of operations needed to satisfy the condition: A[i]
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
91 Views
Suppose we have an array A with n elements. We have to find the length of a non-empty subset of its elements such that their sum is even or return -1 when there is no such subset.So, if the input is like A = [1, 3, 7], then the output will be 2, because sum of [1, 3] is 4.StepsTo solve this, we will follow these steps −n := size of A for initialize i := 0, when i < n, update (increase i by 1), do: if A[i] mod 2 is same as 0, then: ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
211 Views
Suppose we have two numbers n and k. Let we are trying to generate a string S with only three types of characters 'a', 'b' and 'c'. The maximum length of a substring of the string S that is a palindrome which does not exceeds k.So, if the input is like n = 3; k = 2, then the output will be "aab", because its length is 3 and the palindrome substring is "aa" with length at least 2. (other answers are also possible).StepsTo solve this, we will follow these steps −S := a blank string j := 0 for ... Read More