Programming Articles - Page 1447 of 3363

Validate IPv4 address using ReGex patterns in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:57:29

3K+ Views

Given an IP Address, the task is to validate this IP address and check whether it is IPv4 or not with the help of ReGex(Regular Expression). If the IP Address is valid then print “IPv4 Address” otherwise print “Not”.A valid IPv4 address is an IP in the form "X1.X2.X3.X4" where 0

Valid Sudoku in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:57:03

3K+ Views

Let’s suppose we’ve given a 9×9 matrix called a Sudoku. The task is to check whether the given Sudoku Pattern is valid or not.In general, a Sudoku board look like this, Rules of Sudoku −Every row contains a number in the range 1-9Every column contains numbers in the range 1-9.Each block of 3×3 contains unique numbers in it.A particular row cannot have the same number.A particular column cannot have the same number.For ExampleInput-1 −sudoku[]=    [["3", "5", ".", ".", "2", ".", ".", ".", "."]    , ["7", ".", ".", "1", "6", "5", ".", ".", "."]    , [".", "9", "8", ... Read More

Update the bit in the given position or Index of a number using C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:56:21

2K+ Views

In the given problem, we have to update the bit of the given index of a number. To update the number, we can use Bit Manipulation operation on a given number. For example, Input-1 −N= 25 bit= 1 position= 2Output −29Explanation − Since the given input 25 can be written in binary as ‘11001’ whereas the position index is ‘2’ and the bit is ‘1’. After replacing the digits at the given position the output will be ‘11101’ which is equivalent to ‘29’.Approach to solve this problemIn the given position or index of a number, the task is to update ... Read More

static_assert in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:55:01

449 Views

static_assert is a function which is useful for programmers to print the error in the screen after compiling the program without messing up with the output too much.Earlier in C++11 and C++14, static_assert had different functionality which means we have to write our own message while defining the static_assert. However, In C++ 17 static_assert can be invoked without passing the message.It is compatible with other asserts libraries functions like BOOST_STATIC_ASSERT as well.Syntax{    auto __range= For-range-Intializer;    auto __begin= begin-expression;    auto __end= end-expression;    for(; __begin!= __end; ++__begin){       range-declaration= *__begin;       statement    } ... Read More

Square of a sorted array in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:54:29

2K+ Views

In the given array of sorted integers, the task is to print the squares of every array element and print the array in sorted order. For example, Input-1 −arr[ ] = { -3, -1, 0, 1, 4, 6 };Output −{0, 1, 1, 9, 16, 36}Explanation − The squares of each of the elements of the given array [-3, -1, 0, 1, 4, 6 ] is [0, 1, 1, 9, 16, 36 ].Input-2 −arr[ ]= { 0, 1, 2, 8, 9 }Output −{0, 1, 4, 64, 81}Explanation − The squares of each of the elements of the given array [ 0, ... Read More

Sort an arrays of 0’s, 1’s and 2’s using Java

Dev Prakash Sharma
Updated on 05-Feb-2021 12:53:48

472 Views

Given an array of 0, 1 and 2 sort the element in an order such that all the zeros come first before 1 and all the 2’s in the end. We have to sort all the elements of the array in-place.We can solve this problem using DNF (Dutch National Flag) Sorting Algorithm. For example, Input-1 −arr[ ]= {2, 0, 0, 1, 2, 1 }Output −0 0 1 1 2 2Explanation − Sorting the given array of elements containing 0, 1 and 2 using the DNF Sorting Algorithm, it will print the output as {0, 0, 1, 1, 2, 2}.Input-2 −arr[ ... Read More

Sort an arrays of 0’s, 1’s and 2’s using C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:53:04

1K+ Views

Given an array of 0, 1, and 2, sort the elements in an order such that all the zeros come first before 1 and all the 2’s in the end. We have to sort all the elements of the array in-place.We can solve this problem using DNF (Dutch National Flag) Sorting Algorithm. For example, Input-1 −arr[ ]= {2, 0, 0, 1, 2, 1 }Output −0 0 1 1 2 2Explanation − Sorting the given array of elements containing 0, 1 and 2 using DNF Sorting Algorithm, it will print the output as {0, 0, 1, 1, 2, 2}.Input-2 −arr[ ]= ... Read More

Significance of Lambda Function in C/C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:51:35

4K+ Views

Lambda Function − Lambda are functions is an inline function that doesn’t require any implementation outside the scope of the main program.Lambda Functions can also be used as a value by the variable to store. Lambda can be referred to as an object that can be called by the function (called functors).Whenever the compiler encounters a definition of the lambda function, it generally creates a custom object for the lambda.A lambda function has more functionality than a normal function, for example, it has a capturing method to capture the used variables. However, the captured variable is treated as the member ... Read More

Search an element in the given singly Linked List using C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:50:20

661 Views

Given a singly linked list, the task is to search a particular element in the linked list. If the element is found, then print “present” otherwise “Not present”. For example, Input-1 −1→ 2→ 3→ 4→ 5→ 6Searching for ‘7’Output −Not PresentExplanation − In the given singly linked list the element ‘7’ is not present, hence we will return the output as “Not Present”.Input-2 −1→ 2→ 3→ 4→ 5Searching for ‘2’Output −PresentExplanation − Since in the given Singly linked list the element ‘2’ is present thus we will return the output as “Present”.Approach to solve this problemThere are two approaches to ... Read More

Write a program in Java to rotate a matrix by 90 degrees in anticlockwise direction

Dev Prakash Sharma
Updated on 05-Feb-2021 12:49:35

2K+ Views

Let’s suppose we have given a square matrix of N×N. The task is to rotate the matrix counterclockwise. For example, Input-1 −N = 3 matrix[ ][ ] = [    [1 2 3],    [4 5 6],    [7 8 9] ]Output −3 6 9 2 5 8 1 4 7Explanation: After rotating the matrix counterclockwise it will generate the output as, 3 6 9 2 5 8 1 4 7.Approach to solve this problemInitially the idea is to find the transpose of the given matrix and then swap each of the elements of the matrix while traversing row-wise.Take Input ... Read More

Advertisements