http://www.codeoj.com/problemshow.jsp?q=PRACTICEP28&c=PRACTICE
#include <bits/stdc++.h>
#define MAX 1001
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int arr[MAX]={0};
long long int n,x;
cin>>n>>x;
int i=0;
while(n!=0)
{
arr[i]=n%2;
n=n/2;
i++;
}
int arr2[MAX];
fill(arr2,arr2+1000,2); //marked non flips with 2
int len1=i;
for(int j=0;j<len1;j++)
{
if(arr[j]==1)
arr2[j]=0;
}
int arr1[MAX]={0};
i=0;
while(x!=0)
{
arr1[i]=x%2;
x=x/2;
i++;
}
int len2=i;
i=0;
int y=0;
while(y<len2)
{
if(arr2[i]==2)
{ arr2[i]=arr1[y]; y++; i++; }
else
i++;
}
for(int u=i;u<1000;u++)
{
if(arr2[u]==2)
arr2[u]=0;
}
long long int res=0;
for(int f=0;f<1000;f++)
{
res=res+(arr2[f]*pow(2,f));
}
cout<<res<<endl;
}
// your code goes here
return 0;
}
#include <bits/stdc++.h>
#define MAX 1001
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int arr[MAX]={0};
long long int n,x;
cin>>n>>x;
int i=0;
while(n!=0)
{
arr[i]=n%2;
n=n/2;
i++;
}
int arr2[MAX];
fill(arr2,arr2+1000,2); //marked non flips with 2
int len1=i;
for(int j=0;j<len1;j++)
{
if(arr[j]==1)
arr2[j]=0;
}
int arr1[MAX]={0};
i=0;
while(x!=0)
{
arr1[i]=x%2;
x=x/2;
i++;
}
int len2=i;
i=0;
int y=0;
while(y<len2)
{
if(arr2[i]==2)
{ arr2[i]=arr1[y]; y++; i++; }
else
i++;
}
for(int u=i;u<1000;u++)
{
if(arr2[u]==2)
arr2[u]=0;
}
long long int res=0;
for(int f=0;f<1000;f++)
{
res=res+(arr2[f]*pow(2,f));
}
cout<<res<<endl;
}
// your code goes here
return 0;
}
No comments:
Post a Comment