题解 | #进制转换#
进制转换
http://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
string a;
while(cin>>a)
{
int b=0;
for(int i=a.length()-1;i>1;i--)
{
if(a[i]>='0'&&a[i]<='9')
{
b=b+(a[i]-'0')*pow(16,a.length()-1-i);
}
else if(a[i]>='A'&&a[i]<='Z')
{
b=b+((a[i]-'A'+10))*pow(16, a.length()-1-i);
}
}
cout<<b;
}
return(0);
}
#include <cmath>
using namespace std;
int main()
{
string a;
while(cin>>a)
{
int b=0;
for(int i=a.length()-1;i>1;i--)
{
if(a[i]>='0'&&a[i]<='9')
{
b=b+(a[i]-'0')*pow(16,a.length()-1-i);
}
else if(a[i]>='A'&&a[i]<='Z')
{
b=b+((a[i]-'A'+10))*pow(16, a.length()-1-i);
}
}
cout<<b;
}
return(0);
}