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

调了很久。。。。还是WA. 哇哇!

Posted by Lucifer at 2005-09-18 21:55:39 on Problem 2453
#include <iostream.h>
#include <math.h>
#include <stdio.h>
int main()
{
	#ifndef ONLINEJUDGE
		freopen("in.txt","r",stdin);
	#endif
	long n,k,len,m,sum,a[100],i;
	while (cin>>n&&n!=0)
	{
		len=0;
		memset(a,0,sizeof(a));
		while (n>0)
		{
			len++;
			a[len]=n%2;
			n/=2;
		}
		k=0;
		for (i=1;i<=len;i++) if (a[i]==1) break;
		for (;i<=len;i++)
		{
			if (a[i]==0) break;
			else k++;
		}
		if (i==len+1) len++;
		a[i]=1;
		for (m=i-1;m>=k;m--) a[m]=0;
		for (;m>=1;m--) a[m]=1;
		sum=0;
		for (m=1;m<=len;m++)
			sum+=long(powl(2,m-1))*a[m];
		cout<<sum<<endl;
	}
}

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