练习了一下位运算。
poj 2309
#include<stdio.h>
int n,t;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%d %d\n",n-(n&-n)+1,n+(n&-n)-1);
}
}
poj 2453
#include<iostream>
using namespace std;
int n,m,sum1,sum2;
int main()
{
while(cin>>n)
{
if(n==0) break;
sum1=0,sum2=35;
m=n;
while(n)
{
sum1+=n&1;
n>>=1;
}
while(sum1!=sum2)
{
++m;
sum2=0;
int a=m;
while(a)
{
sum2+=a&1;
a>>=1;
}
}
cout<<m<<endl;
}
return 0;
}
poj 3748
#include<stdio.h>
int n,x,y;
int main()
{
int n,x,y;
while(scanf("%x,%d,%d",&n,&x,&y)!=EOF)
{
n&=~(1<<x);
n&=~(7<<(y-2));
n|=6<<(y-2);
printf("%x\n",n);
}
return 0;
}