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

Re:为什么连999都出问题呢?请高人指点

Posted by frkstyc at 2005-04-26 21:50:41 on Problem 1519
In Reply To:为什么连999都出问题呢?请高人指点 Posted by:cpp051000448166 at 2005-04-26 21:45:51
a[]里面的数据串扰了

> #include <iostream>
> using namespace std;
> int i,n,sum,a[100000];
> int boot(int );
> void main()
> {
> 	while (1)
> 	{
> 		cin>>n;
> 		if(n==0)
> 			break;
> 		else
> 			if(n>=10)
> 			{
> 				sum=boot(n);
> 				cout<<sum<<endl;
> 			}
> 			else
> 				cout<<n<<endl;
> 	}
> }
> int boot(int n)
> {
> 	
> 		for(i=0;n>0;i++)
> 		{
> 			a[i]=n%10;
> 			n=n/10;
> 		}
> 		
> 		for(i=0;a[i]>0;i++)
> 		{
> 			n+=a[i];
> 		}
> 		if(n>=10)
> 		n=boot(n);
> 		return n;
> 		
> }

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