Server Side Programming Articles - Page 1753 of 2650

Program to find the largest and smallest ASCII valued characters in a string in C++

Ayush Gupta
Updated on 15-Sep-2020 15:18:18

2K+ Views

In this problem, we are given a string. Our task is to create a program to find the largest and smallest ASCII valued characters in a string in C++.Code Description − Here, we have a string that consists of both upperCase and lowerCase characters. And we need to find the characters that have the largest and the smallest ASCII value character.Let’s take an example to understand the problem, Inputstr = “TutroialsPoint”OutputLargest = u smallest = P.ExplanationAccording to ASCII values, upperCase characters are smaller than lowerCase characters.So, the smallest character of upperCase characters (A) has overall the smallest ASCII value. The ... Read More

Program to find the kth character after decrypting a string in C++

Ayush Gupta
Updated on 08-Jun-2020 10:37:35

232 Views

In this tutorial, we will be discussing a program to find the kth character after decrypting a string.For this, we will be provided with a string that will consist of characters and numbers and integer K. Our task is to decrypt the given string and find the character at Kth position.Example Live Demo#include #include using namespace std; //finding decrypted Kth character char findKthChar(string s, int k) {    int len = s.length();    int i = 0;    int total_len = 0;    while (i < len) {       if (isalpha(s[i])) {          total_len++; ... Read More

Shortest Path to Get All Keys in C++

Arnab Chakraborty
Updated on 08-Jun-2020 10:40:00

588 Views

Suppose we have a grid. There are few symbols. "." is indicating empty cell, "#" is for wall, "@" is for starting point, ("a", "b", ...) all are keys, and ("A", "B", ...) all are locks. We will start from the starting point, and one move consists of walking one space in one of the 4 directions (left, right, top, bottom). We will not go outside the grid, and there are walls to block our way. If we walk over a key, we pick it up. We can't walk over a lock unless we have the corresponding key.For each lock ... Read More

Program to find the initials of a name in C++

Ayush Gupta
Updated on 15-Sep-2020 15:19:16

1K+ Views

In the program, we are given a string name that denotes the name of a person. Our task is to create a Program to find the initials of a name in C++.Code Description − Here, we have to find the initials of the name of the person given by the string.Let’s take an example to understand the problem, Inputname = “ram kisan saraswat”OutputR K SExplanationWe will find all the first letters of words of the name.Solution ApproachA simple solution to the problem is by traversing the name string. And all the characters that appear after the newline character or space ... Read More

Program to find the Interior and Exterior Angle of a Regular Polygon in C++

Ayush Gupta
Updated on 15-Sep-2020 15:20:08

492 Views

In this problem, we are given a number n that denotes the sides of a regular polygon. Our task is to create a Program to find the Interior and Exterior Angle of a Regular Polygon in C++.Problem Description − Here, for the given number of sides, we will find the value of each interior and exterior angle of the regular polygon of side n.Interior Angle is the angle between two adjacent sides of a polygon that lies inside the polygon.Exterior Angle is the angle between two adjacent sides of a polygon that lies outside the polygon.Let’s take an example to ... Read More

Program to find the Hidden Number in C++

Ayush Gupta
Updated on 15-Sep-2020 15:21:21

416 Views

In this problem, we are an array arr[] consisting of n integer values. Our task is to create a Program to find the Hidden Number in C++.Code description − For an array, the hidden number, is the number which when subtracted from each element of the array gives the sum 0.Let’s take an example to understand the problem, Inputarr[] = {4, 1, 6, 7, 2}Output4Subtracting 4 from all elements of the array. And adding of values= (1 - 4) + (6 - 4) + (7 - 4) + (4 - 2) = -3 + 2 + 3 - 2 = ... Read More

Rectangle Area II in C++

Arnab Chakraborty
Updated on 08-Jun-2020 10:35:39

430 Views

Suppose we have a list of (axis-aligned) rectangles. Here each rectangle[i] = {x1, y1, x2, y2}, where (x1, y1) is the point of the bottom-left corner, and (x2, y2) are the point of the top-right corner of the ith rectangle.We have to find the total area covered by all rectangles in the plane. The answer may be very , so we can use modulo 10^9 + 7.So, if the input is likethen the output will be 6.To solve this, we will follow these steps −m = 10^9 + 7Define a function add(), this will take a, b, return ((a mod ... Read More

Program to find the head start in a race in C++

Ayush Gupta
Updated on 15-Sep-2020 15:22:43

164 Views

In this problem, we are given two integers that give the head start that is given by A to B and C respectively in a 100-meter race. Our task is to create a program to find the head start in a race in C++.Code Description − Here, there are head starts that are given by A to B and A to C respectively in a 100-meter race. We need to find the relative head start that is given by B to C in the 100-meter race.Let’s take an example to understand the problem, Input20, 28Output90ExplanationA gives B a head-start of ... Read More

Count Unique Characters of All Substrings of a Given String in C++

Arnab Chakraborty
Updated on 08-Jun-2020 10:32:14

639 Views

Suppose we want to define a function called countUniqueChars(s) that will return the number of unique characters on s, so if s = "HELLOWORLD" then "H", "E", "W", "R", "D" are the unique characters since they appear only once in s, therefore countUniqueChars(s) = 5.Now on this problem given a string s we have to find the sum of countUniqueChars(t) where t is a substring of s. (Here some substrings can be repeated so on this case we have to count the repeated ones too.)As the answer can be very large, we can return answer modulo 10^9+7.So, if the input ... Read More

Making A Large Island in C++

Arnab Chakraborty
Updated on 08-Jun-2020 10:28:50

285 Views

Suppose we have a 2D grid of binary values (0s and 1s), we change at most one 0 to a 1. After that we have to find what is the size of the largest island? Here an island is a 4-directionally (top, bottom, left, right) connected group of 1s.So, if the input is like [[1, 0], [0, 1]], then the output will be 3, this is because if we change one 0 to 1 and connect two 1s, then we will get an island with area = 3.To solve this, we will follow these steps −Define an array dir of ... Read More

Advertisements