tyvj1022 - 进制转换 ——进制为负数

July 8, 2013
tyvj

题目链接:https://www.tyvj.cn/Problem_Show.aspx?id=1022


#include <cstdio>
#include <cstdlib>
#include <cmath>
long long int n, k, r; int a[100];
int main(void) {
    scanf("%lld",&n); int j=0; if(!n){printf("0\n");return 0;}
    while(n) {k=n/(-2); r=n-(-2)*k; if(r==-1) n=k+1,r=1; else n=k; a[j++]=r; }
    for(int k=j-1;k>=0;--k)printf("%d",a[k]);printf("\n");
    return 0;
}

=_=

comments powered by Disqus