16进制转10进制

root 站长 2023-02-01 17:22:36 1
#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, ans = 0;
	string a;
	cin >> n >> a;
	
	//字符串反转
	reverse(a.begin(), a.end()); 

	for (int i = 0; i < a.size(); i ++ )
		if (a[i] >= '0' and a[i] <= '9') ans += (a[i] - '0') * pow(n, i);
		else ans += (a[i] - 'A' + 10) * pow(n, i);
	
	cout << ans;
	return 0;	
}
{{ vote && vote.total.up }}