Found 7347 Articles for C++

C++ code to find out if a grid is fully accessible

Arnab Chakraborty
Updated on 29-Mar-2022 08:36:58

148 Views

Suppose, we are given a grid that has 2 rows and n columns. A robot is at position (0, 0) in the grid and wants to visit (1, n - 1) by visiting adjacent and corner cells to its current location. We are given the grid in an array of strings, a cell is blocked if it is marked '#' and it is accessible if it is marked '.'. We have to find out if the robot can visit cell (1, n - 1) from the cell (0, 0).So, if the input is like n = 4, grid = {".##.", ... Read More

C++ code to decrease even numbers in an array

Arnab Chakraborty
Updated on 29-Mar-2022 08:33:03

204 Views

Suppose, we are given an array 'arr' of size n that contains positive integer numbers. We have to find the even numbers and decrease them by 1. We print out the array after this process.So, if the input is like n = 7, arr = {10, 9, 7, 6, 4, 8, 3}, then the output will be 9 9 7 5 3 7 3.StepsTo solve this, we will follow these steps −for initialize i := 0, when i < n, update (increase i by 1), do:    if arr[i] mod 2 is same as 0, then:       (decrease ... Read More

C++ code to find total elements in a matrix

Arnab Chakraborty
Updated on 29-Mar-2022 08:29:08

158 Views

Suppose, we are given a matrix of n rows and m columns. We have to find out the number of elements present in it. We find out the value and display it as output.So, if the input is like n = 20, m = 15, then the output will be 300.StepsTo solve this, we will follow these steps −return n * mExampleLet us see the following implementation to get better understanding −#include using namespace std; #define N 100 int solve(int n, int m) {    return n * m; } int main() {    int n = 20, m = 15;    cout

What are the differences between C++ and Go?

Bhanu Priya
Updated on 23-Mar-2022 10:40:52

278 Views

Let us understand the concepts of C++ and Go before learning the differences between them.GoIt is an open source programming language developed by Google employees, It is intended to be fast compiled, garbage collected, strongly typed, and with explicit support for concurrent programming.The original developers Rob Pike, Robert Griesemer and Ken Thompson started out in the year 2007. It was licensed under the BSD license. In the case of large systems it supports statically typing and scalability.FeaturesThe features of Go are as follows −Language DesignPowerful standard libraryPackage ManagementStatic TypingTesting SupportC-inspired syntaxCompiledSafe and open sourceAdvantagesThe advantages of Go are as follows ... Read More

C++ code to count maximum hay-bales on first pile

Arnab Chakraborty
Updated on 15-Mar-2022 07:03:37

107 Views

Suppose we have an array A with n elements and another value d. A farmer has arranged n haybale piles on the firm. The ith pile contains A[i] hay-bales. Every day a cow can choose to move one hay-bale in any pile to an adjacent pile. The cow can do this on a day otherwise do nothing. The cow wants to maximize the hay-bales in first pile in d days. We have to count the maximum number of hay-bales on the first pile.So, if the input is like d = 5; A = [1, 0, 3, 2], then the output ... Read More

C++ code to find name with O's on Fibonacci positions

Arnab Chakraborty
Updated on 15-Mar-2022 07:01:34

79 Views

Suppose we have a number n. Amal wants to give a name to his pet. He will follow an algorithm. The name will be n characters long. The name will contain uppercase and lowercase letters 'O's and 'o's. The algorithm suggests the i-th letter of the name should be 'O' (uppercase) if i is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to n.So, if the input is like n = 10, then the output will be "OOOoOooOoo", because first fibonacci numbers are 1, 2, 3, 5 and so on.StepsTo ... Read More

C++ code to find position of students after coding contest

Arnab Chakraborty
Updated on 15-Mar-2022 06:58:57

244 Views

Suppose we have an array A with n elements. In a coding contest, in total n students will participate, and before the start, every one of them has some positive rating (integer). A[i] represents the rating of ith student. After the contest ends, every student will end up with some positive integer position. We are expecting the students will take places according to their ratings. If student A has rating strictly lower than student B, A will get strictly greater position than B. We have to find the position at the end of the contest.So, if the input is like ... Read More

C++ code to find tree height after n days

Arnab Chakraborty
Updated on 15-Mar-2022 06:56:23

157 Views

Suppose we have an array A with n elements. A has elements either 0 or 1. There is a tree. In consecutive n days, if A[i] is 0 it is not watered, if it is 1 then it is watered, the flower grows in the following manner −If the tree is not watered for consecutive two days, it diesIf the tree is watered on ith day, it grows 1 cmIf the tree is watered on ith and (i+1)th day consecutively, it grows 5 cm instead of 1 cm.If it is not watered on ith day, it will not grow.At the ... Read More

C++ code to find minimum different digits to represent n

Arnab Chakraborty
Updated on 15-Mar-2022 06:50:03

110 Views

Suppose we have a number n. We want to split it into some non-zero digits whose sum is n. We want to find a solution with minimum possible number of different digits.So, if the input is like n = 13, then the output will be [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]StepsTo solve this, we will follow these steps −for initialize i := 0, when i < n, update (increase i by 1), do:    print 1ExampleLet us see the following implementation to get better understanding −#include using namespace std; void solve(int n){    for (int i = 0; i < n; i++)       printf("1, "); } int main(){    int n = 13;    solve(n); }Input13Output1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,

C++ code to check all bulbs can be turned on or not

Arnab Chakraborty
Updated on 15-Mar-2022 06:46:48

253 Views

Suppose we have a number m and a nested list A with n sub-lists. Consider there are m bulbs, initially all are turned off. There are n buttons and each of them is connected to some set of bulbs. So A[i] is the set of bulbs that can be turned on by pressing ith switch. We have to check whether we can lit up all the bulbs or not.So, if the input is like A = [[1, 4], [1, 3, 1], [2]]; m = 4, then the output will be True, because by pressing all switches we can turn on ... Read More

Advertisements