满江红求助
查看原帖
满江红求助
1235038
Ekin123楼主2024/9/6 16:53
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

char change(int x)
{
	if(x < 10) return x + '0';
	else return x - 10 + 'A';
}

int change(char c)
{
	if('0' <= c && c <= '9') return c - '0';
	else return c - 'A' + 10;
}

string solve(long long n,int p)
{
	string res = "";
	while(n != 0)
	{
		int r = n % p;
		while(r < 0) r -= p;
		res = change(r) + res;
		n /= p;
	}
	return res;
}

int main()
{
	long long n,p;
	cin >> n >> p;
	string s = solve(n,p);
	cout << n << "=" << s << "(base" << p << ")";
	return 0;
} 

现在认为是 solve() 有问题这还用说吗。

2024/9/6 16:53
加载中...