Simple GUI Notepad Using Ruby

GUI Notepad Using Ruby Code require 'tk' class Notepad def saveFile file = File.open("note", "w") ...

Thursday, January 29, 2015

Programming Problem One

Problem Statement:   Given two numbers (int) L (low) and H (high) , The problem is to find the maximum value of A xor B such that  L ≤ A ≤ B ≤ U.

C++ Code:

  1. #include <iostream>
  2. using namespace std;

  3. int maxXor(int l, int r) 
  4. {
  5. int max = 0;
  6. for (int i = l; i <= r; ++i) {
  7. for (int j = l; j <= r; ++j) {
  8. if((i ^ j) >= max) {
  9. max = i ^ j;
  10. }
  11. }
  12. }
  13. return max;
  14. }
  15.  
  16. int main() 
  17. {
  18. int res, l, r;
  19.  
  20. cin >> l;
  21. cin >> r;
  22.  
  23. res = maxXor(l, r);
  24. cout << res;
  25.   return 0;
  26. }