题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <bits/stdc++.h>
using namespace std;
int qmi(int a,int b){
int res=1;
while(b){
if(b&1)res=res*a;
a=a*a;
b>>=1;
}
return res;
}
int main() {
string str;
cin>>str;
int b=str.length()-2;
int res=0;
for(int i=str.length()-1,j=0;i>1;i--,j++){
int x=str[i]-'0';
if(str[i]>='A'&&str[i]<='F')x=10+str[i]-'A';
res+=x*qmi(16,j);
}
cout<<res;
return 0;
}