AR16

#include <iostream>
using namespace std;
void printTwoOdd(int arr[], int size) 

    int xor2 = arr[0];
    int set_bit_no;
    int i; 
    int n = size - 2; 
    int x = 0, y = 0;
    for(i = 1; i < size; i++) 
        xor2 = xor2 ^ arr[i]; 
    set_bit_no = xor2 & ~(xor2-1);
    for(i = 0; i < size; i++) 
    {
        if(arr[i] & set_bit_no) 
        x = x ^ arr[i]; 
        else
        y = y ^ arr[i]; 
    } 
  if(x>y)
    cout<<x<<" "<<y<<endl; 
  else
    cout<<y<<" "<<x<<endl;
}
int main() 

  int t;
  cin>>t;
  while(t--)
  {
    int arr[100],arr_size;
  cin>>arr_size;
  for(int i=0;i<arr_size;i++)
  {
    cin>>arr[i];
  }
    printTwoOdd(arr, arr_size); 
  }
    return 0; 
}

11 comments:

  1. this code isnt working bruh, that file directory error is showing up , for iostream

    ReplyDelete
  2. Replies
    1. if(x>y)
      cout<y)
      cout<<x<<" "<<y<<endl;
      else
      cout<<y<<" "<<x<<endl;

      Delete
    2. change it into
      if(x>y)
      cout<<x<<" "<<y<<" "<<endl;
      else
      cout<<y<<" "<<x<<" "<<endl;

      Delete
  3. there is a new ques. AR7 plz add it in ur blog
    (
    The kingdom of Vijaygarh had a wise and kind King. People were happy. But the King himself was sad and worried.

    A devilish snake had entered his son’s body. Neither medicine nor magic worked to cure his son.

    So the peoples try to change the mind set of the king about his son. So they created mind related programming activity.

    Now king is watching this mind related activity. the master is giving the questions to the user like, You are given a list of size N, initialized with zeroes.

    You have to perform M operations on the list and output the maximum of final values of all the N elements in the list.

    For every operation, you are given three integers a,b and k and you have to add value k to all the elements ranging from index a to b(both inclusive).

    Mandatory variable declaration is "long long int A[200009];"

    Input Format

    First line will contain two integers N and M separated by a single space.

    Next M lines will contain three integers a,b and k separated by a single space.

    Numbers in list are numbered from 1 to N.

    Output Format

    A single line containing maximum value in the updated list.
    TEST CASE 1

    INPUT
    5 3
    1 2 100
    2 5 100
    3 4 100
    OUTPUT
    200
    TEST CASE 2

    INPUT
    4 3
    2 3 603
    1 1 286
    4 4 882
    OUTPUT
    882

    )

    ReplyDelete
  4. #include
    using namespace std;
    void printTwoOdd(int arr[], int size)
    {
    int xor2 = arr[0];
    int set_bit_no;
    int i;
    int n = size - 2;
    int x = 0, y = 0;
    for(i = 1; i < size; i++)
    xor2 = xor2 ^ arr[i];
    set_bit_no = xor2 & ~(xor2-1);
    for(i = 0; i < size; i++)
    {
    if(arr[i] & set_bit_no)
    x = x ^ arr[i];
    else
    y = y ^ arr[i];
    }
    if(x>y)
    cout<>t;
    while(t--)
    {
    int arr[100],arr_size;
    cin>>arr_size;
    for(int i=0;i>arr[i];
    }
    printTwoOdd(arr, arr_size);
    }
    return 0;
    }




    this code gives 100% for me

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete

SRM ELAB SOLUTUONS   DATA-STRUCTURE                                                                             **IF THE PROGRAM DON...