题解 | 进制转换
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <cmath> #include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string str; while(cin >> str){ reverse(str.begin(),str.end()); } int temp = 0; for(int i = 0 ; i < str.size(); i++){ if( str[i] >= '0' && str[i] <= '9' ){ temp = temp + (str[i] - '0') * pow(16,i); }else if(str[i]>= 'A' && str[i] <= 'F'){ temp = temp + (str[i] - 'A' + 10) * pow(16,i); }else{ continue; } } cout << temp <<endl; return 0; } // 64 位输出请用 printf("%lld")
我这样做,也是很好的方法,倒过来挺好用的;