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 Liuzhaoliang at 2014-09-24 04:19:56 on Problem 3191
int main(){
    int n;
    cin>>n;
    if(n==0) {
        printf("0\n");
        return 0;
    }
    int bit[50],cnt=0;
    int sign = 1;
    if(n<0) n=-n, sign = -1;
    while(n){
        int a = 0;
        if(n&1){
            bit[cnt++]=1;
            if(sign<0) a = 1;
        }else bit[cnt++]=0;
        sign = -sign;
        n/=2, n+=a;
    }
    for(int i=cnt-1;i>=0;i--) printf("%d",bit[i]);
    printf("\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