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 huxinjie800 at 2009-08-05 01:31:34 on Problem 2453
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
	//	freopen("jieguo1.txt","w",stdout);
	//	freopen("shuzi.txt","r",stdin);
	int t,sum,i,k,j;
	bool a[150];
	cin>>t;
	while(t!=0)
	{
		for(i=0;i<149;i++)a[i]=0;
		sum=0;
		for(i=0;;i++)
		{
			a[i]=t%2;
			t=t/2;
			if(t==0)break;
		}
		k=i;
		for(i=0;i<=k;i++)
		{
			if(a[i]==1)
			{
				if(a[i+1]==0)
				{
					a[i]=0;
					a[i+1]=1;
					break;
				}
				else 
				{
					j=i;
					while(a[j-1]==0)
					{
						a[j]=0;
						a[j-1]=1;
						j--;
					}
				}
			}
		}
		for(i=k+5;i>=0;i--)
			sum+=a[i]*pow(2.0,i);
		cout<<sum<<endl;
		cin>>t;
	}
	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