题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/deb19498bc644f53a6a99905ef5ee01d
#include <iostream> #include "stack" #include "cmath" using namespace std; int charToInt(char c) { if (c <= '9' && c >= '0')return c - '0'; else if (c >= 'A' && c <= 'F')return c - 'A' + 10; else return c - 'a' + 10; } int main() { string a; while (cin >> a ) { // 注意 while 处理多个 case // cout << b << endl; long long ans=0; for (int i = a.size() - 1; i >= 2; i--) { ans += charToInt(a[i]) * pow(16, a.size() - 1 - i); } cout<<ans<<endl; } } // 64 位输出请用 printf("%lld")