C++ Articles

Page 392 of 597

Sorting of Vector of Tuple in C++ (Ascending Order)

Rinish Patidar
Rinish Patidar
Updated on 21-Aug-2023 2K+ Views

We will discuss sorting the vector of Tuple in C++ in ascending order in this article. A list of elements are stored in a C++ data structure known as a tuple. The same or different data types may be contained in it, and we may access them in the same sequence in which they were initialised as inputs. A tuple's data is organised so that we can retrieve it in the same order. Syntax tuple name In C++, this is how we can initialise a tuple. We may require few more tuple functions to sort the vector ...

Read More

How to Turn on a Particular Bit in a Number?

Rinish Patidar
Rinish Patidar
Updated on 21-Aug-2023 383 Views

The problem statement says that we need to turn on a particular bit in a number. To put it simply, all we have to do is swap out a certain bit in a number for 1. Provide the same outcome if it has already been 1. You can represent an integer using binary numbers, which come in the forms of 0 and 1 where every digit represents a power of 2. Let's represent 5 in the binary numbers. The binary form of 5 will be 101 i.e.$\mathrm{2^{2} + 2^{0}= 5.}$ In this problem, a number N will ...

Read More

Check if three Straight Lines are Concurrent or Not

Rinish Patidar
Rinish Patidar
Updated on 21-Aug-2023 554 Views

The problem includes checking if the three given straight lines are concurrent or not. If all three lines in a plane pass through the same point, they are said to be concurrent. They must intersect with each other exactly at one point to be concurrent. The three concurrent lines are depicted in the above illustration. According to the above illustration, the point of intersection of any two lines should be located on the third line to be concurrent. The point of concurrence is the intersection of these lines.As everyone is aware, a straight line can be written as ...

Read More

Program to construct a DFA to check if a given integer is unsigned or not

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 506 Views

In this problem, we need to check whether the given number is an unsigned integer using the DFA. We need to construct the DFA using the 2D array to solve the problem. Problem statement – We have given string str of length N. By constructing the DFA, we need to check whether the str represents the unsigned integer. In the output, print ‘unsinged integer’ or ‘Not an unsinged integer’ according to whether the number is unsinged or not. Sample examples Input– str = "1729" Output– “Unsigned integer.” Explanation– As the number doesn’t contain any sign, it is an ...

Read More

Python Program to check if two sentences can be made the same by rearranging the words

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 272 Views

In this problem, we need to check whether we can make two strings equal by rearranging the words of the string. We will learn three different approaches to solving the problem. In the first approach, we will use a dictionary. In the second approach, we will use the sort() method, and in the third approach, we will use the counter() constructor, which is used to count the hashable objects in the python. Problem statement – We have given a str1 and str2 containing sentences. We need to check whether we can make both strings equal by rearranging the words of ...

Read More

Sort an array of strings by replacements with their GCD with elements from another array

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 200 Views

In this problem, we have given two arrays of strings. We need to replace array1’s values to sort array1. To replace the values of array1, we can take the GCD of the current string of array1 with any string of array2. The GCD of the string is very similar to the GCD of the number. To solve the problem, we can find a GCD string lexicographically larger than the GCD of the string at the ith index in array1 and the jth index in array2. Problem statement – We have given array1 and array2 containing the strings, and the length ...

Read More

Modify characters of a string by adding integer values of same-indexed characters from another given string

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 277 Views

In this problem, we need to modify the given string by adding the value of the digit from the num string to the ASCII value of str’s character. To solve the problem, we can convert the digit character to the actual digit and add it to the ASCII value of the character. If the ASCII value becomes greater than 122, we start again from 97. Problem statement – We have given two strings of the same length equal to N. The first string, named str, contains the lowercase alphabetical characters, and the second string, named num, contains digits only. ...

Read More

Reverse alternate k characters in a string

Sonal Meenu Singh
Sonal Meenu Singh
Updated on 18-Aug-2023 473 Views

Introduction In this tutorial, we implement examples using C++ programming logic to reverse the alternate k characters in an input string. We define the value of k to reverse the characters in a given string. K is the number of characters to be reversed. The value of k can be anything. If the value of k is more than the total number of characters in the string we do not reverse any of the string characters. Demonstration 1 String = “tutorialspoint” K = 4 Output otutrialiopsnt In the above demonstration, we consider a string “tutorialspoint” to ...

Read More

Range Queries to find the Element having Maximum Digit Sum

Sonal Meenu Singh
Sonal Meenu Singh
Updated on 18-Aug-2023 391 Views

Introduction In this tutorial, we discuss the problem of range queries to find the element having Maximum Digit Sum in C++. To solve the problem, take an array of elements and some queries. The queries denote the indices of the array and using those queries find the array element with the maximum digit sum. Maximum digit sum is the highest sum of two digit numbers (addition of ones and tens place digits) or one digit number. For example: 12, its sum is 3 (1 + 2). In this tutorial, by using the queries find such a number that has a ...

Read More

Queries for the Count of Even Digit Sum Elements in the given Range using Segment Tree

Sonal Meenu Singh
Sonal Meenu Singh
Updated on 18-Aug-2023 218 Views

Introduction In this tutorial, we implement an approach in C++ to resolve queries for the count of even digit sum elements in the given range. We use a segment tree. To solve this task, we consider an array of elements with queries defining the range of the subarray. In that subarray count the even digit sum elements. Predefine the element array and the queries to resolve the problem using the Segment tree. What is a segment tree? A segment tree is a binary data structure that stores array interval or segment information. It efficiently solves range or segment query problems. ...

Read More
Showing 3911–3920 of 5,962 articles
« Prev 1 390 391 392 393 394 597 Next »
Advertisements