1 条题解

  • 0
    @ 2025-10-8 16:53:10
    #include <bits/stdc++.h>
    using namespace std;
    int a[9];
    int main() 
    {
        int x;scanf("%d", &x);
        memset(a, 0, sizeof(a));
        if(x > 0)
        {
            a[8] = 0;
            for(int i = 1; i <= 7; i++)
            {
                a[i] = x % 2;
                x = x / 2;
            }
        }
        else
        {
            a[8] = 1; x = -x;
            for(int i = 1; i <= 7; i++)
            {
                a[i] = x % 2;
                x = x / 2;
            }
            for(int i = 1; i <= 7; i++) a[i] = 1 - a[i];
            a[1] = a[1] + 1;
            for(int i = 1; i <= 7; i++)
                if(a[i] > 1)
                {
                    a[i] = 0;
                    a[i + 1]++;
                }
        }
        for(int i = 8; i >= 1; i--) printf("%d", a[i]);
        return 0;
    }
    

    • 1

    信息

    ID
    65
    时间
    1000ms
    内存
    128MiB
    难度
    5
    标签
    递交数
    188
    已通过
    76
    上传者