//还以为会涉及到大数的问题,不过并没有。那这道题就直接换算就行了 #include "stdio.h" #include "string" #include "math.h" using namespace std; int main(){ char buf[100]; char change[17] = "0123456789ABCDEF";//用数组下标表示16进制,eg:A的下表为10,那么A代表10 while (fgets(buf,100,stdin)!=NULL){ string num = buf; num.pop_back(); long long sum = 0; for (int i = num.size()-1; i > 1; --i) { int j; for (j = 0; j < 17; ++j) { if (change[j] == buf[i]) break; } sum += pow(16,num.size()-i-1)*j; } printf("%lld\n",sum); } }