Found 7197 Articles for C++

Remove all occurrences of a word from a given string using Z-algorithm

Siva Sai
Updated on 27-Oct-2023 15:50:54

332 Views

This article delves into an interesting string manipulation problem: "Remove all occurrences of a word from a given string using Z-algorithm". This problem serves as an excellent use case for the Z-algorithm, highlighting its efficacy in pattern searching problems. Let's explore in detail. Problem Statement Given a string S and a word W, the task is to remove all occurrences of W from S using the Z-algorithm. Understanding the Problem Consider a string S = "HelloWorldHelloWorld" and a word W = "World". The goal is to remove all occurrences of W from S. Hence, the output would be "HelloHello". Z-algorithm ... Read More

Rearrange a string to maximize the minimum distance between any pair of vowels

Siva Sai
Updated on 27-Oct-2023 15:48:55

220 Views

In this article, we are going to unravel an interesting problem from the domain of string manipulation: "Rearrange a string to maximize the minimum distance between any pair of vowels". This problem challenges us to manipulate the arrangement of characters in a string to ensure the maximum possible minimum distance between any two vowel characters. We'll discuss the problem in detail, providing the various programs. Understanding the Problem Statement Given a string, the task is to rearrange the characters in the string in such a way that the minimum distance between any pair of vowels is maximized. In other words, ... Read More

Random password generator in C

Siva Sai
Updated on 18-May-2023 14:00:09

2K+ Views

In this article, we will delve into an interesting and practical problem related to string manipulation in C programming. We are going to build a "Random Password Generator" in C. This problem not only enhances your understanding of string manipulation but also your knowledge of the C Standard Library. Problem Statement The task is to build a program that generates a random password of a specified length. The password should include uppercase and lowercase alphabets, digits, and special characters. C Solution Approach To solve this problem, we'll leverage the power of the C Standard Library. We'll use the rand() function ... Read More

Program to construct DFA for Regular Expression C( A + B)+

Siva Sai
Updated on 27-Oct-2023 15:46:19

1K+ Views

In this article, we will be discussing how to construct a Deterministic Finite Automaton (DFA) for the Regular Expression C(A + B)+. We'll start by understanding the problem and the theory behind it, then we'll dive into the implementation and conclude with a relevant example to demonstrate its use. Understanding the Problem Statement A Deterministic Finite Automaton (DFA) is a theoretical model of computation used in automata theory, a branch of theoretical computer science. It's one of the simplest types of automata and an essential concept in the study of compilers and parsers. The task here is to program a ... Read More

Print a sorted list of words represented by the expression under the given grammar

Siva Sai
Updated on 27-Oct-2023 15:17:57

184 Views

In this article, we will be exploring an interesting problem related to expressions and grammar. The problem statement is "Print a sorted list of words represented by the expression under the given grammar". This problem offers a great opportunity to brush up your knowledge on parsing expressions, handling strings, and sorting algorithms. Problem Statement Given a string expression where each character represents a lowercase English letter and the '|' character represents an OR operation, the task is to print a sorted list of all possible words represented by the expression. Solution Approach Our approach to solve this problem is by ... Read More

Permutation of a number whose sum with the original number is equal to another given number

Siva Sai
Updated on 27-Oct-2023 15:16:19

353 Views

In this article, we'll delve into a fascinating problem that involves numbers and permutations: "Permutation of a number whose sum with the original number is equal to another given number". This problem offers a unique intersection of number theory and combinatorics, making it a compelling challenge to tackle. To clarify, given an original number and a target number, we need to find a permutation of the original number such that, when we add the original number and its permutation, we get the target number. Understanding the Problem In essence, this problem combines the concepts of number permutation, summation, and equality ... Read More

Move all digits to the beginning of a given string

Siva Sai
Updated on 27-Oct-2023 15:13:54

247 Views

In this article, we will explore a common string manipulation problem: moving all digits to the beginning of a given string. This task is often seen in data cleaning or preprocessing, where we need to standardize or reformat strings in a certain way. A widely-used programming language celebrated for its efficiency and control. Problem Statement Given a string that contains alphanumeric characters, our task is to move all the digits present in the string to the beginning, while keeping the order of the rest of the characters the same. Solution Approach Our approach to solving this problem involves two key ... Read More

Modify string by rearranging vowels in alphabetical order at their respective indices

Siva Sai
Updated on 18-May-2023 12:25:24

214 Views

In this article, we will discuss how to modify a given string in C++ by rearranging the vowels in alphabetical order at their respective indices. We will also explain the approach used to solve this problem and provide an example with a test case. Problem Statement Given a string, rearrange the vowels in alphabetical order at their respective indices. The consonants in the string should remain in their original order. For example, given the string "tutorialspoint", the output should be "tatiriolspount". Approach The problem can be solved using a simple algorithm. We can first create a separate string that contains ... Read More

Modify string by inserting characters such that every K-length substring consists of unique characters only

Siva Sai
Updated on 18-May-2023 12:23:02

186 Views

A common task when working with strings is to make sure that a string adheres to certain conditions. One of these conditions could be to ensure that every substring of length K in the string contains unique characters only. This is a frequent requirement in problems related to data encoding, string manipulation, and cryptography. Problem Statement The problem we are trying to solve can be stated as follows − Given a string str and an integer K, modify the string by inserting characters such that every substring of length K in the string contains unique characters only. Proposed Solution We ... Read More

Modify string by increasing each character by its distance from the end of the word

Siva Sai
Updated on 27-Oct-2023 15:11:34

262 Views

When working with strings, sometimes we need to modify them in specific ways to meet certain requirements. One such requirement is to modify a string by increasing each character by its distance from the end of the word. In this article, we will discuss an approach to solving this problem. Problem Statement Given a string S, modify the string by increasing each character by its distance from the end of the word. Approach To solve this problem, we can follow the following steps − Tokenize the given string S into individual words. Iterate over each word and for each ... Read More

Advertisements