Subset XOR

QUESTION

Given a set S. Generate T, a set that contains all subsets of S minus the null set and calculate A, XOR sum of the set T. \n\nS={1,2,3}\nT={{1},{2},{3},{1,2},{1,3},{2,3} ,{1,2,3}}\nA=XORiana of T .\nXORiana of a set is defined as XOR of all the elements it contains.\n\nConstraints:\n1<=T<=100\n1<=N<=100\n0<=Array[i]<=200.

ANSWER

#include <iostream>
using namespace std;
 
// Returns XOR of all XOR's of given subset
int findXOR(int Set[], int n)
{
    // XOR is 1 only when n is 1, else 0
    if (n == 1)
       return Set[0];
    else
       return 0;
}
 
// Driver program
int main()
{
  int arr[10],tc,n;
  cin>>tc;
  for(int i=0;i<tc;i++)
  {
    cin>>n;
    for(int j=0;j<n;j++)
      cin>>arr[j];
    //int Set[] = {1, 2, 3};
    //int n = sizeof(Set)/sizeof(Set[0]);
    cout<< findXOR(arr, n);
    cout<<endl;
  }
    return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro