题解 | 进制转换
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream>
#include<cmath>
using namespace std;
int main() {
int a, b,num;
num = 0;
string str;
cin>>str;
str = str.substr(2);
for(int i=0;i<str.size();i++)
{
if(str[i]>='0'&&str[i]<='9')
{//这部分又要牵扯一下ascii码。字符之间的运算能自动转换为ascii之间的运算
num =num+ (str[i]-'0')*pow(16, str.size()-i-1);//指数最高是 长度-1
}
else {
num =num+( str[i]-'A'+10)*pow(16,str.size()-i-1);
}
}
cout<<num;
while (cin >> a >> b) { // 注意 while 处理多个 case
cout << a + b << endl;
}
}
// 64 位输出请用 printf("%lld")
查看20道真题和解析