![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements