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 xuchang at 2011-01-14 11:24:04 on Problem 2282
#include <iostream>
#include <math.h>
using namespace std;
int count[10];
int temp[10];
int c=1;
void add(int v,int t)
{
	while(v!=0)
	{
		int x=v%10;
		count[x]+=t;
		v/=10;
	}
}

void search(int v)
{
	if(c>=10)
		count[0]-=c;
	int x=v/10;
	int y=v%10;
	for(int i=0;i<=y;i++)
		count[i]+=c;
	add(x,(y+1)*c);
	if(x!=0)
	{
		for(int i=0;i<=9;i++)
			count[i]+=x*c;
		c*=10;
		search(x-1);
	}
}

int main()
{
	while(true)
	{
		int a,b;
		cin>>a>>b;
		if(a==0&&b==0)
			break;
		if(a>b)
		{
			int tt=a;
			a=b;
			b=tt;
		}
		search(a-1);
		memcpy(temp,count,10*sizeof(int));
		memset(count,0,10*sizeof(int));
		c=1;
		search(b);
		for(int i=0;i<9;i++)
			cout<<count[i]-temp[i]<<" ";
		cout<<count[9]-temp[9]<<endl;
		memset(count,0,10*sizeof(int));
		c=1;
	}
	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