这题的测试用例有问题,不可能全AC
2025-09-21 12:06:59
发布于:安徽
5阅读
0回复
0点赞
这题最后一个测试用例是 15 FFFFFFFFFF,15进制怎么可能有F
下面是正确的转进制代码
#include<iostream>
#include<string>
using namespace std;
string DIG = "0123456789ABCDEFGHIJK";
int to_Ten(int base, string &numStr)
{
int result = 0;
int value;
for (char c : numStr)
{
value = DIG.find(c);
if (value >= base || value == string::npos)
{
cout << "输入的内容和不合法";
}
else
{
result = result * base + value;
}
}
return result;
}
int main()
{
int base;
cin >> base;
string numStr;
cin >> numStr;
cout << to_Ten(base, numStr);
}
这里空空如也
有帮助,赞一个