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

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.