文章

2

粉丝

0

获赞

3

访问

73

头像
十进制和二进制 题解:
P1176 清华大学上机题
发布于2026年1月27日 00:09
阅读数 34

#include<bits/stdc++.h>

using namespace std;


int div2(string &s){
    int remainder = 0;
    for(int i = 0 ; i < s.size() ; i++){
        int current = remainder *10 + (s[i] - '0');
        s[i] = current/2 + '0';
        remainder = current %2;
    }
    while(s.size() > 1 && s[0] == '0')
        s.erase(0,1);
    
    return remainder;

}

string to_bi(string n){
    string s = "";
    if(n == "0") return "0";
    
    while( n != "0"){
        int bit = div2(n);
        s += bit + '0';
    }
    return ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发