Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用位操作

Posted by blue1000 at 2007-07-24 15:05:11 on Problem 2453
找第一对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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator