题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream> #include <string> using namespace std; int main() { string s; int res = 0; int base = 1; getline(cin, s); for (int i = s.size() - 1; i >= 0 && s[i] != 'x'; i--) { int now; if (s[i] <= '9' && s[i] >= '0') { now = s[i] - '0'; } else { switch (s[i]) { case 'A': now = 10; break; case 'B': now = 11; break; case 'C': now = 12; break; case 'D': now = 13; break; case 'E': now = 14; break; case 'F': now = 15; break; } } res += now * base; base = base * 16; } cout << res << endl; return 0; }