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

贴个代码,9进制

Posted by speedcell4 at 2011-02-08 14:58:30 on Problem 2719
#include<stdio.h>
int n;
int pow(int a,int b)
{
    if(b==0) return 1;
    else return a*pow(a,b-1);
}
int wei(int n)
{
    if(n<10) return 1;
    else return 1+wei(n/10);
}
int kan(int n,int i)
{
    if(i==1)
    {
        if(n<4) return n;
        else return n-1;
    }
    else
    {
        int w=pow(10,i-1),z=n/w,q=n%w;
        return kan(z,1)*pow(9,i-1)+kan(q,i-1);
    }
}
int main()
{
    while(scanf("%d",&n),n)
    {
        printf("%d: %d\n",n,kan(n,wei(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