题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream> using namespace std; int main() { string str; getline(cin,str); int len=str.size(); int base=1; int intValue=0; for(int i=len-1;i>1;i--){ char ch=str[i]; int chValue; if(ch>='0'&&ch<='9'){ chValue=ch-'0'; }else if(ch>='A'&&ch<='F'){ chValue=ch-'A'+10; }else if(ch>='a'&&ch<='f'){ chValue=ch-'a'+10; } intValue+=chValue*base; base*=16; } cout<<intValue; } // 64 位输出请用 printf("%lld")