//程序名:新的C++程序
//作者:
#include<string>
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
string s;
int a=0,b=1,n;
int main()
{
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]>='a'&&s[i]<='f'){s[i]=s[i]-32;}
}
for(int i=0;i<s.size();i++)
{
if((s[i]>='0'&&s[i]<='9')||(s[i]>='A'&&s[i]<='F')){a++;}
}
if(a!=s.size()){cout<<"NO";return 0;}
else
{
int n = s.length();
long long num=0;
for(int i = 0; i < n; i++){
if(s[i]>='0'&&s[i]<='9'){
num += (s[i]-'0');
}else if(s[i]>='a'&&s[i]<='f'){
num += (s[i]-'a'+10);
}else if(s[i]>='A'&&s[i]<='F'){
num += (s[i]-'A'+10);
}
if(i<n-1)
{
num *= 16;
}
}
cout<<num;
}
return 0;
}
十六进制(c++)
最新推荐文章于 2024-07-17 09:14:55 发布