文章

273

粉丝

20

获赞

711

访问

146.6k

头像
二进制数 题解:
P1380 北京邮电大学机试题
发布于2026年3月15日 14:53
阅读数 17

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    vector <unsigned int> vec;
    unsigned int n;
    while(cin >> n){
        vec.push_back(n);
    }
    for(int i=0;i<vec.size();i++){
        if(!vec[i]){
            cout << '0' << '\n';
            continue;
        }

//计算二进制位数
        for(int j=log2(vec[i]);j>-1;j--){
            cout << ((vec[i] >> j)&1); 
        }
        cout <<  '\n';
    }...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发