文章

93

粉丝

56

获赞

263

访问

20.4k

头像
0和1的个数 题解:暴力
P1008 华南师范大学/贵州大学机试
发布于2025年3月9日 13:40
阅读数 212

#include <bits/stdc++.h>
using namespace std;

int num[32]={0};

int main()
{
    int n;
    cin>>n;
    int count0=0;
    int count1=0;
        int j=0;
        while(j<32)
        {
            num[j]=n%2;
            n/=2;
            j++;
        }
        for(int j=31;j>=0;j--)
        {
            if(num[j]==0)count0++;
            else count1++;
        }
    cout<<"count0="<<count0<<' '<<&quo...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发