描述
写出一个程序,接受一个十六进制的数,输出该数值的十进制表示。
数据范围:保证结果在
输入描述:
输入一个十六进制的数值字符串。
输出描述:输出该数值的十进制字符串。不同组的测试用例用n隔开。
#includeusing namespace std; int main(){ string str; while(cin >> str){ cout << stoi(str, 0, 16) << endl; } return 0; }
stoi()将n进制数转换为10进制
#includeusing namespace std; int main(){ string str; while(cin >> str){ int res = 0; int pos = str.find('x'); for(int i = pos + 1; i = 'A' && str[i] <= 'F'){ tmp = 10+(str[i] - 'A'); } else{ tmp = str[i] - '0'; } res = res*16 + tmp; } cout << res << endl; } return 0; }



