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

谁能帮帮我,为什么过不了?我在VC上运行都通过了啊!

Posted by ericsummer at 2005-07-23 16:45:10 on Problem 1519
#include <iostream.h>

#include <math.h>

int main()
{
	void digitroot(unsigned long a[] , unsigned long);

	unsigned long digit(unsigned long  a[] , unsigned long);

	unsigned long a[100000];

	unsigned long N;



	while( cin >> N && N)
	{
		
		digitroot(a , digit(a,N));

		cout << a[0] <<endl;


	
	}


	

	return 0;
}

unsigned long  digit(unsigned long a[] , unsigned long N)
{
	unsigned long m;

	unsigned long x=N;

	m = (unsigned long)log10(N);

	for(unsigned long i=0 ; i<= m ; i++)
	{
		a[i]=x%10;

		x/=10;

	}

	return m;
}


void digitroot(unsigned long a[] , unsigned long m )
{
	if(m==0);
		

	else
	{
		unsigned long sum=0;
		
		for(unsigned long i=0 ; i <= m ; i++)
			sum+=a[i];
		
		

		digitroot(a , digit(a,sum));
	}


	
}

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