文章

13

粉丝

43

获赞

4

访问

3.2k

头像
十进制和二进制 题解:
Kohi VIP
P1176 清华大学上机题
发布于2024年3月17日 18:55
阅读数 431

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

string division(string s, const int &from, const int &to, int &remain){
    remain = 0;
    for(int i = 0; i < s.size(); i++){
        int temp = remain * from + s[i] - '0';
        s[i] = temp / to + '0';
        remain = temp % to;
    }
    int pos = 0;
    while('0' == s[pos]){
        pos++;
    }
    return s.substr(pos);
}

string conversion(string s, const int &from, const int &to){
    string ret = "";
    int remain = 0;
    while(0 != s.size()){
        s = division(s, from, to, remain);
        ret += char('0' + remain);
    }
    return ret;
}

int main(){
    string s = "&quo...

登录查看完整内容


登录后发布评论

1 条评论
xxl0609 VIP
2024年3月31日 13:00

六啊

赞(0)