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

POJ2282求教大牛

Posted by james9102 at 2010-08-16 12:37:26 on Problem 2282
#include<stdio.h>
#include<string.h>
void cntdigit(long n,int cnt[],int t)   //以132为例
{
	int i,x,y;
	if(n<=0) return ;
	x=n/10;y=n%10;      
	n=x;
	for(i=0;i<=y;i++)     //计数130,131,132的个位0,1,2
	    cnt[i]+=t;
	for(;x!=0;x/=10)     //计数130,131,132的前两位13
	    cnt[x%10]+=(y+1)*t;
	for(i=0;i<=10;i++)    //计数0-9,10-19,20-29….120-129的个位数
	    cnt[i]+=n*t;
	cnt[0]=cnt[0]-t;//注意要减1(去掉0)
	cntdigit(n-1,cnt,t*10);//计数0-12(注意:乘以10倍)
}
void main()
{
	long a,b,t;
	int i=-1,j,sum1[10]={0},sum2[10]={0};
	while(scanf("%d %d",&a,&b))
	{
		if(a==0&&b==0)  break;
		if(a>b)
		{
			t=a;
			a=b;
			b=t;
		}
		memset(sum1,0,sizeof(sum1));
		memset(sum2,0,sizeof(sum2));//设断点处
		cntdigit(a-1,sum1,1);
		cntdigit(b,sum2,1);
		for(j=0;j<=9;j++)
			printf("%d ",sum2[j]-sum1[j]);
		printf("\n");
	}
}


向高手求教:为什么上述代码在VC中运行是错误输出,在Dev C++是正确输出?关键的问题在于:在VC中函数sum2传值时为什么会将sum1[0]的值改变?本菜鸟喜欢用VC,这个问题让我很困惑。请各路大牛F5试试,在代码设断点处观察为何这样(函数实参传向形参时sum2传值时为什么会将sum1[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