题解 | #进制转换#

进制转换

https://www.nowcoder.com/practice/deb19498bc644f53a6a99905ef5ee01d

#include <iostream>
#include <string>
#include <cmath>
#include <cctype>
using namespace std;
int transfer(char c){
     if(isdigit(c)){
        return c-'0';
     }
     else return  c-'A'+10;
}
int main() {
    string s;
    while (cin >> s) { // 注意 while 处理多个 case
    int res=0,iter=0;
        for(int i=s.size()-1;s[i]!='x';--i){
            res+=transfer(s[i])*pow(16,iter++);
        }
        cout<<res<<endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

昨天 14:31
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务