Codeforces 1362B. Johnny and His Hobbies Solution

  1. Solution in C++:
    ///**********ALLAH IS ALMIGHTY************///
    ///AH Tonmoy
    ///Department of CSE,23rd batch
    ///Islamic University,Bangladesh
  2. #include<iostream>
  3. #include<Set>
  4. using namespace std;
  5. int main()
  6. {
  7. int t,n,i,j;
  8. cin>>t;
  9. while(t--)
  10. {
  11. cin>>n;
  12. int ar[n];
  13. set<int>s;
  14. for(i=0;i<n;i++)
  15. {
  16. cin>>ar[i];
  17. s.insert(ar[i]);
  18. }
  19. int r=-1;
  20. for(i=1;i<=1024;i++)
  21. {
  22. set<int>s1;
  23. s1.clear();
  24. for(j=0;j<n;j++)
  25. {
  26. s1.insert(i^ar[j]);
  27. }
  28. if(s==s1)
  29. {
  30. r=i;
  31. break;
  32. }
  33. }
  34. cout<<r<<endl;
  35. }
  36. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.