牛客网刷题1——进制转换(C++)

题目

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
 int main()
 {
     string s;
     while(cin>>s)
     {
         int bit=0;
         int ans =0;
         for(int i=s.length()-1;i>1;i--)
         {
             if(s[i]>='0'&&s[i]<='9')
                 ans+=(s[i]-'0')*pow(16,bit++);
             else if(s[i]>='A'&&s[i]<='F')
                 ans+=(s[i]-'A'+10)*pow(16,bit++);
         }
         cout<<ans<<endl;
     }
     return 0;
 }
发布了56 篇原创文章 · 获赞 29 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_41122796/article/details/104786783