题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream> #include<map> using namespace std; int main() { map<char,int> Map; Map['0']=0; Map['1']=1; Map['2']=2; Map['3']=3; Map['4']=4; Map['5']=5; Map['6']=6; Map['7']=7; Map['8']=8; Map['9']=9; Map['A']=10; Map['B']=11; Map['C']=12; Map['D']=13; Map['E']=14; Map['F']=15; string s; while (cin >> s) { // 注意 while 处理多个 case int n=s.size(); int result=0; for(int i=2;i<n;i++){ result+=Map[s[i]]; if(i!=n-1) result*=16; } cout<<result<<endl; } } // 64 位输出请用 printf("%lld")