Found 7197 Articles for C++

C++ code to find answers by vowel checking

Farhan Muhamed
Updated on 04-Aug-2025 19:02:44

248 Views

In this article, we will explain a beginner level problem that involves finding answers for questions by checking for vowels in the question text. We will implement a C++ program that solves this problem. Let's break down the problem statement below. Find Answers by Vowel Checking Amal and Bimal are playing a game. Amal will ask any questions whose answers will be either "Yes" or "No". If the question’s last letter is a vowel, then Bimal will answer "Yes" otherwise "No". You are given a string containing the question that Amal asks. Your task is to determine the answer ... Read More

C++ code to find center of inner box

Arnab Chakraborty
Updated on 29-Mar-2022 11:42:12

396 Views

Suppose we have a matrix of size n x m. Cells are either 'W' as white or 'B' as black. Some square inside the table with odd length was painted black. We have to find the center of this square.So, if the input is likeWWBBBWWWBBBWWWBBBWWWWWWWWWWWWWthen the output will be (3, 1).StepsTo solve this, we will follow these steps −n := row count of matrix m := column count of matrix cnt := 0 X := 0 Y := 0 for initialize i := 0, when i < n, update (increase i by 1), do:    for initialize j := 0, ... Read More

C++ code to find greater number whose factor is k

Arnab Chakraborty
Updated on 29-Mar-2022 11:37:21

192 Views

Suppose we have two numbers n and k. We have to find smallest integer x which is greater than n and divisible by k.So, if the input is like n = 5; k = 3, then the output will be 6.StepsTo solve this, we will follow these steps −return n + k - (n mod k)ExampleLet us see the following implementation to get better understanding −#include using namespace std; int solve(int n, int k){    return n + k - n % k; } int main(){    int n = 5;    int k = 3;    cout

C++ code to check pile count is valid from second day

Arnab Chakraborty
Updated on 29-Mar-2022 11:35:35

205 Views

Suppose we have two arrays X and Y of same size. There are stone piles with X[i] number of stones on ith index on the first day and on the second day ith index has Y[i] number of stones. On the first day many members have come. Either they do nothing or they add few stones to some pile or they swap few stones from one pile to another. We have to check whether Y is valid from X or not.So, if the input is like X = [1, 2, 3, 4, 5]; Y = [2, 1, 4, 3, 5], ... Read More

C++ code to find minimum k to get more votes from students

Arnab Chakraborty
Updated on 29-Mar-2022 11:33:28

243 Views

Suppose we have an array A with n elements. There are n students in a school and each of them has exactly k votes and all votes should be used. There are two parties. The A[i] represents ith student has given A[i] amount of votes to first party and this implies the second party will get k- A[i] number of votes. The second party wants to set k in such a way that they win. What will be the minimum possible value of k.So, if the input is like A = [2, 2, 3, 2, 2], then the output will ... Read More

C++ code to check triangular number

Arnab Chakraborty
Updated on 29-Mar-2022 11:31:34

1K+ Views

Suppose we have a number n. We have to check whether the number is triangular number or not. As we know, if n dots (or balls) can be arranged in layers to form a equilateral triangle then n is a triangular number.So, if the input is like n = 10, then the output will be True.StepsTo solve this, we will follow these steps −for initialize i := 1, when i

C++ code to find corrected text after double vowel removal

Arnab Chakraborty
Updated on 29-Mar-2022 11:27:52

166 Views

Suppose we have a string S with n character. On a text editor, there is a strange rule. The word corrector of this text editor works in such a way that as long as there are two consecutive vowels in the word, it deletes the first vowel in a word. If there are no two consecutive vowels in the word, it is considered to be correct. We have to find corrected word from S. Here vowels are 'a', 'e', 'i' 'o', 'u' and 'y'.So, if the input is like S = "poor", then the output will be "por".StepsTo solve this, ... Read More

C++ code to count steps to reach final position by robot

Arnab Chakraborty
Updated on 29-Mar-2022 11:24:46

377 Views

Suppose we have two coordinates (x1, y1) and (x2, y2). A robot is at the point (x1, y1) and wants to go to the point (x2, y2). In a single step, the robot can move towards one cell to its 8 adjacent coordinates. We have to find minimal number of steps needed to reach the final position.So, if the input is like x1 = 3; y1 = 4; x2 = 6; y2 = 1;, then the output will be 3, becauseStepsTo solve this, we will follow these steps −return maximum of |x2 - x1| and |y2 - y1|ExampleLet us see ... Read More

C++ code to count numbers after division elements greater than half of array size

Arnab Chakraborty
Updated on 29-Mar-2022 11:20:32

162 Views

Suppose we have an array A with n elements. We have to find some non-zero integer d, such that such that, after each number in the array is divided by d, the number of positive values that are presented in the array is greater than or equal to the half of the array size. If there are multiple values of d that satisfy the condition. If there are multiple answers, return any one of them.So, if the input is like A = [10, 0, -7, 2, 6], then the output will be 4, because here n = 5 , so ... Read More

C++ code to find who cannot give sufficient candies

Arnab Chakraborty
Updated on 29-Mar-2022 11:17:25

160 Views

Suppose we have two numbers a and b. There are a and b number of candies in Amal's and Bimal's hand. Amal offered 1 candy to Bimal and Bimal gave two candies to Amal, in the next turn Amal gave 3 candies and Bimal gave 4 and so on. This continued until the moment when one of them couldn’t give the right amount of candy. They don’t consider the candies they have got from the opponent, as their own. We have to find, who is the first can’t give the right amount of candy.So, if the input is like a ... Read More

Advertisements