結果

問題 No.2385 Parse Integer with Radix
ユーザー kpinkcatkpinkcat
提出日時 2023-10-03 02:15:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 199,084 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-03 02:15:40
合計ジャッジ時間 3,367 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<iostream>
#include<map>
#include<vector>
#include <algorithm>
#include<math.h>
#include <iomanip>
#include<set>
#include <numeric>
#include<string>
using ll = long long;
using namespace std;

int main(){
    ll q;
    cin >> q;
    for (int i = 0; i < q; i++){
        string s;
        cin >> s;
        ll n = 0, p = 0, mul = 0;
        if (s.size() <= 2){
            cout << s << endl;
            continue;
        } else if (s[1] == 'b'){
            p = 2;
            mul = 2;
        } else if (s[1] == 'o'){
            p = 8;
            mul = 8;
        } else if (s[1] == 'x'){
            p = 16;
            mul = 16;
        } else {
            cout << s << endl;
            continue;
        }
        if (s.back() >= '0' && s.back() <= '9') n += (s.back() - '0');
        else n += ((s.back() - 'a') + 10);
        s.pop_back();
        while (s.size() > 2){
            int num = 0;
            if (s.back() >= '0' && s.back() <= '9') num += (s.back() - '0');
            else num += ((s.back() - 'a') + 10);
            s.pop_back();
            n += num*p;
            p *= mul;
        }
        cout << n << "\n";
    }
}
0