题解 | #进制转换#
进制转换
http://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include<iostream> #include<string> #include<math.h> using namespace std; int main() { string str; while (getline(cin, str)) { int res = 0; for (int i = str.length()-1,j=0; i > 0; i--,j++) { if (str[i] >= 'A' && str[i] <= 'F') { res += (str[i]-55) * pow(16,j); } else if (str[i] == 'x') { break; } else { res += (str[i] - 48) * pow(16, j); } } cout << res << endl; } }