题解 | 进制转换
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include<cmath> #include <iostream> #include<string> using namespace std; using ll=long long; int main() { string s; cin>>s; string k=s.substr(2); int j=0;ll ans=0; for(int i=(int)k.size()-1;i>=0;i--) { if(k[i]>='0'&&k[i]<='9') { ans=ans+(k[i]-'0')*pow(16,j++); } else if(k[i]>='A'&&k[i]<='F') { ll num=k[i]-'A'+10; ans+=num*pow(16,j++); } } cout<<ans<<endl; } // 64 位输出请用 printf("%lld")
//也是个模拟吧,我讲几个点,首先肯定是好习惯开long long。
//然后就是substr的截取运用,吧ox给去掉,然后再倒序去看k的每个数。然后在外面搞个计数器j就行了