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 swust20051578 at 2007-10-16 11:57:11 on Problem 2402
#include<iostream>
using namespace std;

int main(void)
{
	int i,m=9,k;
	unsigned __int64 b,q,n;
	__int64 a[30];
	a[0] = 9;
	a[1] = 9;
	for(i=2; i<30; i++)
	{
		a[i] = a[i-2]*10;
	}
	while(scanf("%I64d",&n)&&n)
	{
        
		
		i=0;
		while(1)
		{	
			if(n<a[i])
			{
				b = n + a[i]/9-1;
				break;
			}
			if(n==a[i])
			{
				b = 0;
				for(k=0;k<=i;k++)
				{
					b += a[k];
				}
				if(!(i%2))
				{
					b = a[k] + (b-a[k])/2;
				}
				else
				{
					if(i>0)
						b = a[k] + (b-2*a[k])/2;
				}
				break;
			}
			if(n>a[i])
			{
				n = n-a[i];
				i++;
			}
			
		}
		q = b;
		fprintf(stdout,"%I64d",q);
		if(i%2)
		{
			fprintf(stdout,"%I64d",b%10);
			b = b/10;
		}
		else
		{
			b = b/10;
		}
		while(b!=0)
		{
			fprintf(stdout,"%I64d",b%10);
			b = b/10;
		}
		cout<<endl;
	}
	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