题解 | #进制转换#

进制转换

https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6

#include <iostream>
#include <string>
#include <cctype>
#include <cmath>
using namespace std;
// 输出描述有奇怪了  不是就输入一个 吗 为啥提到说用换行符隔开
int main() {
    long long ans;
    string d;

    // while (cin >> a >> b) { // 注意 while 处理多个 case
    //     cout << a + b << endl;
    // }
    getline(cin, d);

    int l = d.size();

    for(int i=l-1; i>=2; i--)
    {
        int s = l-1 - i;
        char ch = d[i];
        // 字符转整型
        long long chn;
        if(!isalpha(ch)) // 是数字
        {
            chn = int(ch-'0'); // 坑在这里 字符到Int  这里不能 直接int() 那个是asicii2码
        }
        else
        {
            ch = tolower(ch);
            chn = (ch - 'a')+10; // 类似的 相减 在传唤解码
        }
        
        ans += chn*pow(16., s); 

    }

    cout<<ans;

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

2025-12-10 19:36
湖北工业大学 Web前端
饿魔:看到在线简历了吧
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
2025-12-19 10:45
秋招路在何方:少了啊,我身边都是350000k*18,发三体货币
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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