题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream>
using namespace std;
#include <cmath>
int main() {
string str;
while(cin>>str){
string num16=str.substr(2,str.size()-2);//保存十六进制的值
int res=0;
int count=0;
int j=0;
for(int i=num16.size()-1;i>=0;i--){
if(num16[i]>='A'){
count=num16[i]-'A'+10;//字母转数值
}else{
count=num16[i]-'0';//数字转数值
}
res+=count*pow(16,j);//每一位的值乘16的j次方
j++;
}
cout<<res<<endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")
小米集团公司福利 866人发布