为啥错了
查看原帖
为啥错了
752045
Nazi_ljx_weiren楼主2024/3/22 22:48
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int n, b,x=0,y=0;
string a;
string nn = "0123456789ABCDEF";
int c[11] = { 0 };
int main()
{
	cin >> n >> a >> b;
	for (int i = a.length() - 1; i >= 0; i--)
	{
		int dd;
		if (a[i] >= '0' && a[i] <= '9')
		{
			dd = a[i] - '0';
		}
		if (a[i] >= 'A' && a[i] <= 'Z')
		{
			dd = a[i] - 'A' + 10;
		}
		if (a[i] >= 'a' && a[i] <= 'z')
		{
			dd = a[i] - 'a' + 10;
		}
		dd = dd * pow(n, x);
		x++;
		y += dd;
	}
	int w = 0;
	if (y == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	while (y != 0)
	{
		c[w] = y % b;
		y /= b;
		w++;
	}
	for (int i = w-1; i >= 0; i--)
	{
		cout << nn[c[i]];
	}
	cout << endl;
	return 0;
}

记录

记录

两个代码相同为啥第二个有一个re

2024/3/22 22:48
加载中...