Codeforces 1362B. Johnny and His Hobbies Solution
- Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh - #include<iostream>
- #include<Set>
- using namespace std;
- int main()
- {
- int t,n,i,j;
- cin>>t;
- while(t--)
- {
- cin>>n;
- int ar[n];
- set<int>s;
- for(i=0;i<n;i++)
- {
- cin>>ar[i];
- s.insert(ar[i]);
- }
- int r=-1;
- for(i=1;i<=1024;i++)
- {
- set<int>s1;
- s1.clear();
- for(j=0;j<n;j++)
- {
- s1.insert(i^ar[j]);
- }
- if(s==s1)
- {
- r=i;
- break;
- }
- }
- cout<<r<<endl;
- }
- }
No comments