ในบทช่วยสอนนี้ เราจะอภิบายโปรแกรมเพื่อหาจำนวนควอดรูเปิลจาก 4 อาร์เรย์ ที่ XOR ของพวกเขาเท่ากับ x
สำหรับเรื่องนี้ เราจะได้รับ 4 อาร์เรย์และค่า x งานของเราคือนับควอดรูเปิลทั้งหมดที่ XOR เท่ากับค่า x ที่กำหนด
ตัวอย่าง
#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;
}เอาต์พุต
4