Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我用的不是九进制,我用的是递归的思路,也ac了#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator