Found 26504 Articles for Server Side Programming

XOR Cipher in C++

sudhir sharma
Updated on 17-Apr-2020 12:28:55

3K+ Views

XOR cipher or XOR encryption is a data encryption method that cannot be cracked by brute-force method.Brute-force method is a method of random encryption key generation and matching them with the correct one.To implement this encryption method, we will define an encryption key(random character) and perform XOR of all characters of the string with the encryption key. This will encrypt all characters of the string.Program to show the implementation of encryption −Example Live Demo#include #include using namespace std; void XORChiper(char orignalString[]) {    char xorKey = 'T';    int len = strlen(orignalString);    for (int i = 0; i < len; ... Read More

XOR of a subarray in C++

sudhir sharma
Updated on 17-Apr-2020 12:14:06

142 Views

In this problem, we are given an arr[] and some queries that are range between L to R in the array. Our task is to print the XOR of the subarray between L to R.Let’s take an example to understand the problem, Input − array = {1, 4, 5, 7, 2, 9} L = 1 , R = 5Output −Explanation − 4^5^7^2^9To solve this problem, we will create an array, based on the following observation, We will XOR multiple bits, if there are odd number of 1s, the result will be 1 otherwise the result is 0.Now, we will create ... Read More

XOR of a submatrix queries in C++

sudhir sharma
Updated on 17-Apr-2020 12:41:02

168 Views

In this problem, we are given a N x N matrix and some queries, each query contains the top-left and bottom-right corner of the submatrix created from this matrix. Our task is to find the XOR of all elements of the submatrix defined by the querries.Let’s take an example to understand the problem, Inputarr[][] = {{1, 2, 3} {4, 5, 6} {7, 8, 9}} Querries: {0, 0, 1, 2} , {1, 2, 2, 2}Output1 15Explainationquerry 1 : 1^2^3^4^5^6 querry 2 : 6^9To solve this problem, we will find a prefix-XOR matrix to solve queries. The value of the matrix at ... Read More

log1p() in C++ program

Sunidhi Bansal
Updated on 17-Apr-2020 12:07:18

126 Views

We are given with a variable of any type and the task is to find the result using the function log1p(). log1p() is an analytical function that takes an argument ‘a’ and also has a return value.Syntaxdouble log1p (double x); Where x ranges between [-1, ?] float log1p (float x);Return Type − This function returns a non-zero value if the argument is greater than -1 else it will return a non-numeric value.ExampleInputa = 20.34Output3.06058Inputa = 0.0Output0Example Live Demo#include #include using namespace std; int main(){    double ans = 20.34;    double temp;    temp = log1p(ans);    cout

XOR of all elements of array with set bits equal to K in C++

sudhir sharma
Updated on 17-Apr-2020 12:36:26

290 Views

In this problem, we are given an array of n elements and an integer value k. Our task is to find XOR of all elements of the array that have set bits equal to k.Let’s take an example to understand the problem, Inputarray = {2, 12, 44, 103, 17} , K =3Output44To solve this problem, we will count set bit of every element of the array and compare it with k. If the number of set bits is equal to k, then we will push it to a vector and find XOR of all elements of the vector.For finding the ... Read More

mbrtowc() function in C/C++ program

Sunidhi Bansal
Updated on 17-Apr-2020 12:04:58

194 Views

In this article we will be discussing the working, syntax and examples of std::mbrtowc() function in C++ STL.What is std::mbrtowc()?std::mbrtowc() function is an inbuilt function in C++ STL, which is defined in the header file. mbrtowc() means that it converts the narrow multibyte character string to wide character. This function is used to convert a narrow multibyte character to wide character representation.Syntaxsize_t mbrtowc( wchar_t* pwc, char* str, size_t n, mbstate_t* ps);ParametersThe function accepts following parameter(s) −pwc − This is the pointer to the location we want the output to be stored.str − Character string which is used as the ... Read More

Z algorithm (Linear time pattern searching Algorithm) in C++

sudhir sharma
Updated on 17-Apr-2020 11:26:30

1K+ Views

Z algorithm is used to find the occurrence of a pattern in a string in linear time. Suppose if the length of the string is n and the size of the pattern to be searched is m, the time taken to solve will be of the order O(m+n).The z-algorithm uses a Z array to find the occurrence of a pattern.Z arrayIt is an array of the same length as the string. Each element of the z-array consists of the length of the longest substring of the string starting from I which can be used as a prefix of the string ... Read More

Z-Buffer or Depth-Buffer method in C++

sudhir sharma
Updated on 17-Apr-2020 11:20:45

2K+ Views

The z-buffer also known as depth-buffer is a method that is used for hidden surface detection.Hidden surface detectionFor any picture that has objects and surfaces that are transparent. In this case, objects that are behind other objects are hidden. For proper visual of the image, we need to remove these hidden surfaces is required. The identification is called hidden surface problem.In z-buffer, we will compare surfaces in the z-axis as depths.AlgorithmStep 1: initialize the depth of all pixel max.    d(i, j) = infinity Step 2: Initialize color for all pixels.    c(i, j) = background-color Step 3: for each ... Read More

Zero Initialization in C++

sudhir sharma
Updated on 17-Apr-2020 11:18:30

1K+ Views

Zero initialization is setting the initial value of an object in c++ to zero.SyntaxT{} ; char array [n] = “”;The situations in which zero initialization are performed are −Named variable with static or thread-local storage is initialized to zero.It is used as initialization of values for non-class types and members of a class that do not have a constructor.It is used to initialize a character array when its length is greater than the number of characters that are to be assigned.Points to rememberSome types of variables like static variables and thread-local variables are first initialized to zero then reinitialized to ... Read More

Zig Zag Level order traversal of a tree using single queue in C++

sudhir sharma
Updated on 17-Apr-2020 11:15:53

278 Views

In this problem, we are given a binary tree. Our task is to print the zigzag level order traversal of the tree. For this traversal, we will use a single queue only.Let’s take an example to understand the problem, Output −3    1    7    2    8    9    5To solve this problem using a single queue, we will sue an extra separation flag along with the queue and direction flag.Now, we will traverse the tree level by level, insert root element, now insert for every element of the queue insert its child node to the queue. ... Read More

Advertisements