题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream>
#include <string>#include <algorithm>
#include <cmath>
using namespace std;
int main() {
string str;
int num = 0;
while (cin >> str) {
num = 0;
string subs = str.substr(2);
int len = subs.size();
for (int i = 0; i < len; i++) {
char c = subs[i];
if (c >= '0' && c <= '9') {
c = c - '0';
} else if ( c >= 'A' && c <= 'F') {
c = c - 'A' + 10;
}
num += c * pow(16, len-i-1);
}
cout<<num<<endl;
if (cin.get()=='\n'){
break;
}
}
}