题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream>
#include <string>
#include <cmath>
int main(int argc, char* argv[]){
std::string str;
std::cin >> str;
int res = 0;
int i = 0;
int j = str.size() - 1;
while(str[j] != 'x'){
int num;
if(str[j] >= '0' && str[j] <= '9'){
num = str[j] - '0';
}
else {
num = str[j] - 55;
}
res += pow(16, i) * num;
--j;
++i;
}
std::cout << res <<std::endl;
return 0;
}