Found 34494 Articles for Programming

Count ways to Split a String into two Subsets that are Reverse of Each Other

Aishwarya Mani Tripathi
Updated on 08-Sep-2023 17:37:37

84 Views

In this tutorial, we delve into the problem of dividing a given string into two non-empty subsets, where the first subset is the reverse of the second subset. We aim to provide an efficient solution to count the number of ways to achieve such partitions. By leveraging the power of the C++ programming language, we present a solution that utilizes bitmasking and string manipulation techniques to iterate through all possible partitions and validate them against the given condition. We will explore the step-by-step implementation of the solution, discussing the algorithm and code structure. Additionally, we will provide a ... Read More

Count Possible Decoding of a given Digit Sequence with Hidden Characters

Aishwarya Mani Tripathi
Updated on 08-Sep-2023 17:34:14

190 Views

Count possible decoding of a given digit sequence with hidden characters is a fascinating problem in the realm of string decoding. In this tutorial, we delve into the challenge of decoding a sequence of digits that may contain hidden characters denoted by asterisks ('*'). The task at hand is to determine the number of ways these hidden characters can be decoded, taking into account a specific mapping of letters from A to Z to the digits 1 to 26. We present an efficient solution using the power of C++ programming language and dynamic programming techniques. By ... Read More

Check if the String formed by the first and last X characters of a String is a Palindrome

Aishwarya Mani Tripathi
Updated on 08-Sep-2023 17:27:15

59 Views

In this tutorial, we will explore a problem statement that involves checking whether a string, formed by combining the first X characters and the last X characters of a given string, is a palindrome or not. A palindrome refers to a sequence of characters that remain unchanged when reading both forwards and backwards. The task is to determine if the resulting combined string, derived from the specified characters at the beginning and end of the original string, exhibits palindrome properties. To accomplish this, we will delve into an effective solution using the C++ programming language. By breaking ... Read More

Check if a given pattern exists in a given string or not including wild cards * and .

Aishwarya Mani Tripathi
Updated on 08-Sep-2023 17:31:18

150 Views

Check if a given pattern exists in a given string or not including wild cards * and . is a common problem in computer science and programming. In this problem, we are given a string (text) and a pattern, which can contain wildcard characters '*' and '.', and we need to check if the pattern matches the text or not. This problem is encountered in a wide range of applications, such as search engines, file systems, and network protocols. In this tutorial, we will discuss a simple and efficient solution to this problem using C++. We will start ... Read More

Check if a permutation of S2 can be obtained by adding or removing characters from S1

Aishwarya Mani Tripathi
Updated on 08-Sep-2023 16:51:05

57 Views

Checking if a permutation of S2 can be obtained by adding or removing characters from S1 is a common problem in computer science. This problem is of great significance in various domains, including data processing, text analysis, and pattern recognition. In this tutorial, we will be presenting a solution to this problem using C++ programming language. The approach involves analyzing the characteristics of S1 and S2 to establish whether S2 can be rearranged to form a permutation of S1. We will be providing the C++ code for this approach along with explanations to help readers understand the problem ... Read More

Tech number in Swift

Ankita Saini
Updated on 08-Sep-2023 15:59:09

96 Views

If the given number contains an even number of digits and the digits of the number can be divided into two equal parts from the middle. After dividing the digits sum up the divided digits and find the square of the final sum. If the square is equal to the sum itself then the given number is a tech number otherwise not. Example Demonstration Input 3025 Output Yes the given number is a tech number Input 2341 Output No the given number is not a tech number Here, 3025 is a ... Read More

Swift Program to Print Floyd’s Triangle

Ankita Saini
Updated on 08-Sep-2023 15:56:06

146 Views

Floyd triangle is right angle triangled which is named after Rober Floyd. It is created with the help of natural numbers starting from 1 in the top left corner and then the consecutive numbers are filled in the specified rows. Example Demonstration Input 4 Output 1 2 3 4 5 6 7 8 9 10 Here, the size of Floyd’s triangle is 4. So it will print Floyd’s triangle until 4 rows. In Swift, we can print Floyd’s triangle using the following methods: Using for−in loop Using while loop Using recursive function Algorithm ... Read More

How to Write Calculator Program using Switch Case in Swift

Ankita Saini
Updated on 08-Sep-2023 15:51:06

519 Views

A Calculator is an electronic device which is used to perform different types of mathematical operations like subtraction, addition, division, multiplication, etc. We can also create a calculator using Switch case and simple arithmetic operations in Swift programming. It will also perform the same mathematical operations as the original calculator. Example Demonstration Enter any two numbers: Number 1: 43 Number 2: 234 SIMPLE CALCULATOR 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Percentage Choose (1/2/3/4/5): 2 Result = -191.0 Here, we first enter the numbers on which we want to perform the ... Read More

How to Swap Pair of Characters in Swift?

Ankita Saini
Updated on 08-Sep-2023 15:35:03

235 Views

Swapping pair of characters is a process of interchanging the position of two characters in the given string. This operation is commonly used in various programming languages and applications to manipulate data. Example Input “mumbai” Output umbmia Input “Prita” Output rPtia Here, we divide the given string into a pair of characters like “mumbai”: “mu”, “mb”, “ai”. Now we swap the positions of the characters: “um”, “bm”, and “ia” and create the resultant string: “umbmia”. Similarly for input 2. In Swift, we can swap the pair of characters present in the given ... Read More

How to Calculate the Volume of a Tetrahedron in Swift?

Ankita Saini
Updated on 08-Sep-2023 15:30:27

61 Views

Tetrahedron is a triangular base pyramid. It is a platonic solid with four triangular faces, six straight edges and four vertex corners. Where each vertex is connected with every other vertex and each face is of an equilateral triangle. In Swift, we can calculate the volume of a tetrahedron using the following formula: Formula $$\mathrm{Area=(x*x*x*\sqrt{2})/12}$$ Here, x represents the sides of the tetrahedron. Algorithm Step 1 − Create a function which takes the side of the tetrahedron as a parameter and returns the volume. Step 2 − Inside the function, we use the mathematical formula to find the volume ... Read More

Advertisements