题解 | #二进制数#

二进制数

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

#include <iostream>
#include <utility>
#include <vector>
using namespace std;
void getBinary(int x){
    vector<int> v;
    while(x != 0){
        v.push_back(x % 2);
        x /= 2;    
    }
    for(int i = v.size() - 1; i >= 0; i --)
        cout << v[i];
    cout << endl;
}
int main() {
    int x;
    while (cin >> x) {
        getBinary(x);
    }
    return 0;
}

全部评论

相关推荐

spiritecs:没实习非985211硕很难很难,只能说祝早日成功
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务