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 litstrong at 2008-07-06 16:51:39 on Problem 2719
#include "stdio.h"
long an(long n)
{
	long k=1,nn=n,sum1=0,sum2=0;
	if(n<4)  return n;
	if(n>4&&n<10)  return n-1;
	while(nn){
		if(nn%10>4)  sum2+=k;
		nn/=10;
		sum1+=an(nn)*k;
		k*=10;
	}
	return n-sum1-sum2;
}
void main()
{
	long n;
	scanf("%ld",&n);
	while(1){
		if(n==0)  break;
		printf("%ld: %ld\n",n,an(n));
		scanf("%ld",&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