#include <iostream>#include<string.h>#include<math.h>using namespace std;//十六进制转化为十进制 int main(int argc, char** argv) { char c[8]; int arr[8]; //arr存基数 gets(c); int len = strlen(c); for(int k = 0;k < len;k++ ){ switch(c[k]){ case 'A': arr[k] = 10; break; case 'B': arr[k] = 11; break; case 'C': arr[k] = 12; break; case 'D': arr[k] = 13; break; case 'E': arr[k] = 14; break; case 'F': arr[k] = 15; break; default: arr[k] = c[k] - '0'; } }long long int sum = 0; //sum保存最终结果 for(int g = 0;g < len;g++ ){ int a = pow(16,len-g-1); sum = sum + arr[g]*a; } cout << sum <<endl; return 0;}
添加回答
举报
0/150
提交
取消