Server Side Programming Articles - Page 520 of 2650

C++ code to check given flag is stripped or not

Arnab Chakraborty
Updated on 29-Mar-2022 11:53:56

302 Views

Suppose we have a matrix of size n x m. Each cell will hold one value from 0 to 9. There is a flag should be striped: each horizontal row of the flag should contain squares of the same color, and the colors of the adjacent horizontal rows should be different. We have to check given matrix is valid flag or not.So, if the input is like000111333StepsTo solve this, we will follow these steps −n := row count of matrix m := column count of matrix l := 'm' res := 1 for initialize i := 0, when i < ... Read More

C++ code to find minimum correct string from given binary string

Arnab Chakraborty
Updated on 29-Mar-2022 11:49:30

172 Views

Suppose we have a binary string S with n bits. There are no redundant leading zeroes. We can perform two different operations on S −Swap any pair of adjacent bitsReplace all "11" with "1"Let val(S) is decimal representation of S. We have to find minimum correct string, where correct string A is less than another correct string 'B' when val(A) < val(B)So, if the input is like S = "1001", then the output will be 100, because we can perform the operation like "1001" -> "1010" -> "1100" -> "100".StepsTo solve this, we will follow these steps −n := size ... Read More

C++ code to find answers by vowel checking

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

257 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

403 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

201 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

Java Program to Determine the Unicode Code Point at a given index

AmitDiwan
Updated on 29-Mar-2022 11:39:21

435 Views

In this article, we will understand how to determine the unicode code point at a given index. Each character is represented by a unicode code point. A code point is an integer value that uniquely identifies the given character. Unicode characters can be encoded using different encodings, like UTF-8 or UTF-16.Below is a demonstration of the same −Suppose our input is −Input String: Java Program Index value: 5The desired output would be −Unicode Point: 80AlgorithmStep 1 - START Step 2 - Declare a string value namely input_string and two integer values namely index and result Step 3 - Define the ... Read More

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

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

223 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

260 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

Java program to print first letter of each word using regex

AmitDiwan
Updated on 29-Oct-2024 00:38:40

807 Views

In this article, we will understand how to print the first letter of each word using regex. A regular expression is a sequence of characters that forms a search pattern. A regular expression can be a single character or a more complicated pattern. A regular expression helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern. They can be used to search, edit, or manipulate text and data. Problem Statement Write a program in Java to print the first letter of each word using regex. Below is a demonstration of the same ... 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

Advertisements