C++ 十进制转任意进制算法 - 详解与实现
#include
using namespace std;
string convertToBaseR(int N, int R) { string result;
while (N > 0) {
int remainder = N % R;
if (remainder < 10) {
result += to_string(remainder);
} else {
result += char('A' + remainder - 10);
}
N /= R;
}
reverse(result.begin(), result.end());
return result;
}
int main() { int N, R; cin >> N >> R;
string baseR = convertToBaseR(N, R);
cout << baseR << endl;
return 0;
}
原文地址: http://www.cveoy.top/t/topic/iofY 著作权归作者所有。请勿转载和采集!