[Problem]
将m进制数n转化成一个十进制数 m<=16
题目保证转换后的十进制数<=100
[Solution]
#include <cstdio> #include <cstring> #include <iostream> using namespace std;#define MAX_LEN 101 char table[256];int main(){int m;char n[MAX_LEN];table['A'] = 10;table['B'] = 11;table['C'] = 12;table['D'] = 13;table['E'] = 14;table['F'] = 15;while(cin >> n >> m){int result = 0, base = 1;for(int i = strlen(n) - 1; i >= 0; --i){if(n[i] >= 'A' && n[i] <= 'F'){result += table[n[i]] * base;}else{result += (n[i] - '0') * base;}base *= m;}cout << result << endl;}return 0; }