题解 | #二进制数#

二进制数

https://www.nowcoder.com/practice/103dd589fed14457a673c613d8de3841

#include <iostream>
#include<vector>
using namespace std;

int main() {
    unsigned int x = 0; //别丢int
    while (scanf("%d", &x) != EOF) {
        vector<int> binary;
        while (x != 0) {
            binary.push_back(x % 2);
            x /= 2;
        }
        vector<int>::reverse_iterator it;//反向迭代器
        for (it = binary.rbegin(); it != binary.rend();
                it++) { //rbegin()与rend()获取反向之后的首尾
            printf("%d", *it);
        }
        printf("\n");
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 14:32
点赞 评论 收藏
分享
吴offer选手:HR:我KPI到手了就行,合不合适关我什么事
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务