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

我用的不是九进制,我用的是递归的思路,也ac了

Posted by ccyjava at 2009-08-03 23:08:41 on Problem 2719
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int dig[10];
int getn(int a){
	char arr[11];
	int len;
	int min=0;
	int r;
	itoa(a,arr,10);
	len=strlen(arr);
	
	if(len==1){
		if(a>4)
			return 1;
		else
			return 0;
	}
	min=(arr[0]-'0')*dig[len-2];
	r=getn(atoi(arr+1));
	if((arr[0]-'0')>4)
		min=min-dig[len-2]+pow(10,len-1);
	min=min+r;
	return min;
}


int main(){
	
	int base = 10;
	char arr[11],i;
	int minit=0,n;
	int len;
	dig[0]=1;
	for(i=1;i<10;i++){
		dig[i]=dig[i-1]*10+base-dig[i-1];
		base*=10;
	}
	while(scanf("%d",&n),n!=0){
		minit=getn(n);
		printf("%d: %d\n",n,n-minit);
	}
	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