HJ5题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream> #include <string> #include <math.h> using namespace std; int GetConvertNum(const char ch) { if (ch >= '0' && ch <= '9') { return ch - '0'; } else if (ch >= 'A' && ch <= 'Z') { return ch - 'A' + 10; } else { return -1; } } int main() { string input; int count = 0; getline(cin, input); for (int i = input.size() - 1, j = 0; i >= 0; i--, j++) { if (input[i] == 'x') { break; } int num = GetConvertNum(input[i]); if (num != -1) { count += num * pow(16, j); } else { j--; } } cout << count << endl; }#刷题#