题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
复习先不写了,直接边输入数边计算
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
string s;
int n=0;
cin>>s;
for(int i=2;i<s.size();i++){
n*=16;
if(s[i]>='0'&&s[i]<='9'){
n+=(s[i]-'0');
}else{
n+=(s[i]-'A'+10);
}
}
cout<<n;
}
华为机考题库 文章被收录于专栏
华为题库百题

查看12道真题和解析