| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
用位操作找第一对01,0,1 交换,然后后面的非0 部分移到最右端
#include<iostream>
#include<bitset>
using namespace std;
int main(){
int i,m,l;
bitset<32> I(unsigned(0));
while(scanf("%d",&I)==1){
if(I==0) break;
l=0;
while(!I[l]) l++;
i=l;
while(I[i]) i++;
I.set(i);
I.reset(i-1);
if(l){
for(m=0;m<i-1-l;m++)
I.set(m);
for(;m<i-1;m++)
I.reset(m);
}
printf("%d\n",I);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator