1 条题解

  • 0
    @ 2026-10-2 2:21:40

    C++ :

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #define INF 999999999
    #define N 1001
    using namespace std;
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF&&n)
        {
            int cnt=0;
            int temp=n;
            while(temp>0)
            {
                if(temp%2)
                    cnt++;
                temp/=2;
            }
            int sum=0;
            while(1)
            {
                temp=++n;
                while(temp>0)
                {
                    if(temp%2)
                        sum++;
                    temp/=2;
                }
                if(cnt==sum)
                {
                    cout<<n<<endl;
                    break;
                }
                sum=0;
            }
        }
        return 0;
    }
    
    • 1

    信息

    ID
    3898
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者