题解 | 进制转换

进制转换

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

#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <numeric>
#include <ctime>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <bits/stdc++.h>
#define il inline

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll N = 1e4 + 5, mod = 1e9 + 7, inf = 2e18;

il void solve() {
    string a;
    cin >> a;
    vector<int>p;
    for (int i = 2; i < a.size(); i++) {
        int num = (a[i] > '9' ? a[i] - 'A' + 10 : a[i] - '0');
        p.push_back(num);
    }
    reverse(p.begin(), p.end());
    ll ans = 0, bits = 1;

    for (int i = 0; i < p.size(); i++) {
        ans += p[i] * bits;
        bits *= 16;
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t = 1;

    //cin >> t;

    while (t--) {

        solve();

    }

    return 0;
}

全部评论

相关推荐

10-13 16:58
门头沟学院 Java
点赞 评论 收藏
分享
投递亚信科技(中国)有限公司等公司6个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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