题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream> #include <cmath> using namespace std; int main() { string str; int t = 0; while (cin >> str) { // 注意 while 处理多个 case int i = 0; int bit = 0; for (i = str.length() - 1; i > 1; i--) { if (str[i] == 'A') { t = t + 10 * pow(16, bit); } else if (str[i] == 'B') { t = t + 11 * pow(16, bit) ; } else if (str[i] == 'C') { t = t + 12 * pow(16, bit) ; } else if (str[i] == 'D') { t = t + 13 * pow(16, bit); } else if (str[i] == 'E') { t = t + 14 * pow(16, bit); } else if (str[i] == 'F') { t = t + 15 * pow(16, bit); } else { t = t + (str[i] - '0') * pow(16, bit); } bit = bit + 1; } cout << t << endl; } } // 64 位输出请用 printf("%lld")