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

老runtime error,诡异

Posted by Harrygogogo at 2009-12-12 02:35:39 on Problem 2282
#include<stdio.h>
int f[10];
int count(int x)
{
	int i,a,s,t,d,total=0;
	if(x>0)d=1;else{d=-1;x=-x;}
	a=x;t=1;s=0;
	while(a/10){t*=10;a/=10;s++;}
	for(i=1;i<10;i++)f[i]+=a*s*d*t/10;
	for(i=1;i<a;i++)f[i]+=t*d;
	f[a]+=(x%t+1)*d;
	if(x-x/t*t)count((x-x/t*t)*d);
	t=1;
	for(i=1;i<=s;i++){total+=9*t*i;t*=10;}
	total+=(x-t+1)*(s+1);
	return total;
}
int main()
{
	int i,m,a,b,zero;
	while(scanf("%d%d",&a,&b),a)
	{
		for(i=1;i<10;i++)f[i]=0;
		if(a>b){m=a;a=b;b=m;}
		zero=count(b);
		if(a>1)zero-=count(1-a);
		for(i=1;i<10;i++)zero-=f[i];
		f[0]=zero;
		for(i=0;i<9;i++)printf("%d ",f[i]);
		printf("%d\n",f[9]);
	}
	return 0;
}
这个代码RE,但把f放到函数里面写成count(int f[],int x)就能AC。哪个高手能告诉我为什么?!

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