
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Count all Quadruples from four arrays such that their XOR equals to ‘x’ in C++
In this tutorial, we will be discussing a program to find the number of quadruples from four arrays such that their XOR equals to x.
For this we will be provided with four arrays and a value x. Our task is to count all the quadruples whose XOR is equal to the given value x.
Example
#include<bits/stdc++.h> using namespace std; //counting quadruples with XOR equal to x int count_quad(int a[], int b[], int c[], int d[], int x, int n){ int count = 0; for (int i = 0 ; i < n ; i++) for (int j = 0 ; j < n ; j++) for (int k = 0 ; k < n ; k++) for (int l = 0 ; l < n ; l++) if ((a[i] ^ b[j] ^ c[k] ^ d[l]) == x) count++; return count; } int main(){ int x = 3; int a[] = {0, 1}; int b[] = {2, 0}; int c[] = {0, 1}; int d[] = {0, 1}; int n = sizeof(a)/sizeof(a[0]); cout << count_quad(a, b, c, d, x, n) << endl; return 0; }
Output
4
- Related Articles
- Count quadruples from four sorted arrays whose sum is equal to a given value x in C++
- Find smallest number n such that n XOR n+1 equals to given k in C++
- Count of all possible values of X such that A % X = B in C++
- Count ordered pairs of positive numbers such that their sum is S and XOR is K in C++
- Count Triplets That Can Form Two Arrays of Equal XOR in C++
- Minimum flips in two binary arrays so that their XOR is equal to another array in C++.
- Count minimum bits to flip such that XOR of A and B equal to C in C++
- Find number of pairs in an array such that their XOR is 0 using C++.
- Count of arrays in which all adjacent elements are such that one of them divide the another in C++
- Count all pairs with given XOR in C++
- Count of pairs (x, y) in an array such that x < y in C++
- Find sub-arrays from given two arrays such that they have equal sum in Python
- Count numbers whose sum with x is equal to XOR with x in C++
- Count smaller values whose XOR with x is greater than x in C++
- Find three element from different three arrays such that that a + b + c = sum in Python

Advertisements