基本的进制转换,不过要把16进制的数以字符串的形式输进来,然后进行处理
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
string str;
while(cin >> str){
int ans = 0;
int bit = 0;
for(int i = str.size()-1 ; i > 1 ; i--){
if(str[i] >= '0' && str[i] <= '9'){
ans += (str[i] - '0')*pow(16,bit++) ;
}
else if(str[i] >= 'A' && str[i] <= 'F'){
ans += (str[i] - 'A' + 10)*pow(16,bit++) ;
}
}
cout << ans << endl;
}
}知识点解析:
- 基本进制转换,主要pow(16,bit++)
- cmath库的平方公式,基本公式

京公网安备 11010502036488号