Found 7347 Articles for C++

C++ program to find circumference of the circular pond with radius R

Arnab Chakraborty
Updated on 03-Mar-2022 07:17:43

83 Views

Suppose we have a number R, represents the radius of a pond. We have to find the circumference of this pond.So, if the input is like R = 73, then the output will be 458.67252742410977361942StepsTo solve this, we will follow these steps −res := r * 2 * cos-inverse (-1) return resLet us see the following implementation to get better understandingExampleLet us see the following implementation to get better understanding −#include using namespace std; double solve(int r){    double res = r * 2 * acos(-1);    return res; } int main(){    int R = 73;    cout

C++ program to convert kth character to lowercase

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

147 Views

Suppose we have a string S with N characters. S contains only three types of characters 'A', 'B' or 'C'. We also have another integer K. We have to print S after lowercasing the Kth character in it.So, if the input is like K = 2; S = "AABACC", then the output will be "AaBACC"StepsTo solve this, we will follow these steps −S[K - 1] = S[K - 1] + 32 return SExampleLet us see the following implementation to get better understanding −#include using namespace std; string solve(int K, string S){    S[K - 1] = S[K - ... Read More

C++ program to find string after adding character 'a' string becomes non-palindrome

Arnab Chakraborty
Updated on 03-Mar-2022 07:17:30

99 Views

Suppose we have a string S with lowercase English letters. We must insert exactly one character 'a' in S. After inserting that if we can make S not a palindrome then return that string, otherwise return "impossible".So, if the input is like S = "bpapb", then the output will be "bpaapb"StepsTo solve this, we will follow these steps −if concatenation of S and "a" is not palindrome, then:    return S concatenation 'a' otherwise when concatenation of "a" + S is not palindrome, then:    return 'a' concatenation S Otherwise    return "Impossible"ExampleLet us see the following implementation to get ... Read More

C++ program to find minimum possible difference of largest and smallest of crackers

Arnab Chakraborty
Updated on 03-Mar-2022 07:13:47

237 Views

Suppose we have two numbers N and K. We want to distribute N crackers to K users. We have to find the minimum possible difference between the largest number of crackers received by a user and smallest number received by a user.So, if the input is like N = 7; K = 3, then the output will be 1, because when the users receive two, two and three crackers, respectively, the difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.StepsTo solve this, we will follow these steps −if ... Read More

C++ program to check the coins forms x amount of rupees or not

Arnab Chakraborty
Updated on 03-Mar-2022 07:11:53

117 Views

Suppose we have two numbers K and X. Consider Amal has K, 500 rupee notes. We have to check whether the sums up to X rupees or not.So, if the input is like K = 2; X = 900, then the output will be True, because 2*500 = 1000 and it is not less than 900.StepsTo solve this, we will follow these steps −if (500 * k) >= x, then:    return true Otherwise    return falseExampleLet us see the following implementation to get better understanding −#include using namespace std; bool solve(int k, int x){    if ((500 * k) >= x){       return true;    } else{       return false;    } } int main(){    int K = 2;    int X = 900;    cout

C++ program to count in how many ways we can minimize cable length to connect computers

Arnab Chakraborty
Updated on 03-Mar-2022 07:02:43

210 Views

Suppose we have two arrays A and B both with N elements. Consider there are N computers and N sockets. The coordinate of ith computer is A[i] and coordinate of ith socket is b[i]. These 2N coordinates are pair-wise distinct. We want to connect each computer with a socket by cables. Each socket can be connected at most one computer. We have to count in how many ways we can minimize the length of cables. If the answer is too large, return result mod 10^9 + 7.So, if the input is like A = [0, 10]; B = [20, 30], ... Read More

C++ program to check whether we can distribute bags so that two friends will get same amount of candies

Arnab Chakraborty
Updated on 03-Mar-2022 07:01:58

154 Views

Suppose we have an array A with 4 elements. There are 4 bags of candies, ith bag contains A[i] amount of candies. We want to give each bags to one of our two friends. We have to check whether we can distribute these bags in such a way that each friend receives the same amount of candies in total?So, if the input is like A = [1, 7, 11, 5], then the output will be True, because we can give the first and the third bag to the first friend, and the second and the fourth bag to the second ... Read More

C++ program to count in how many ways we can paint blocks with two conditions

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

268 Views

Suppose we have three numbers N, M and K. Consider there are N blocks they are arranged in a row. We consider following two ways to paint them. The paints of two blocks different if and only if the blocks are painted in different colors in following two ways −For each block, use one of the M colors to paint it. (it is not mandatory to use all colors)There may be at most K pairs of adjacent blocks that are painted in the same color.If the answer is too large, return result mod 998244353.So, if the input is like N ... Read More

C++ program to find two points from two lines who are not same

Arnab Chakraborty
Updated on 03-Mar-2022 06:58:04

253 Views

Suppose we have two ranges (l1, r1), (l2, r2) represents two lines on x-axis. l1 < r1 and l2 < r2. These segments may intersect, overlap or coincide with each other. We have to find two numbers a and b, such that a is in range (l1, r1) and b is in (l2, r2) and a and b are distinct.So, if the input is like l1 = 2; r1 = 6; l2 = 3; r2 = 4, then the output will be a = 3, b = 4, other answers are also possible.StepsTo solve this, we will follow these steps ... Read More

C++ program to find number in given range where each digit is distinct

Arnab Chakraborty
Updated on 03-Mar-2022 06:55:49

425 Views

Suppose we have two numbers l and r. We have to find an integer x, which is in between l and r (both inclusive) and all digits in x are distinct.So, if the input is like l = 211; r = 230, then the output will be 213.StepsTo solve this, we will follow these steps −for initialize k := l, when k

Advertisements