結果

問題 No.2385 Parse Integer with Radix
ユーザー hiro71687khiro71687k
提出日時 2023-07-23 21:17:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,835 bytes
コンパイル時間 7,487 ms
コンパイル使用メモリ 263,652 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 05:16:03
合計ジャッジ時間 6,097 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=998244353 ;
ld inf=10000999999999900;
int main(){
    ll q;
    cin >> q;
    vector<ll>two(60,1);
    for (ll i = 1; i < 60; i++)
    {
        two[i]=two[i-1]*2;
    }
    vector<ll>eight(60,1);
    for (ll i = 1; i < 60; i++)
    {
        eight[i]=eight[i-1]*8;
    }
    vector<ll>zr(20,1);
    for (ll i = 1; i < 20; i++)
    {
        zr[i]=zr[i-1]*16;
    }
    for (ll i = 0; i < q; i++)
    {
        string s;
        cin >> s;
        if (s.size()==1)
        {
            cout << s << endl;
            continue;
        }
        
        if (s[1]<='9'&&s[1]>='0')
        {
            cout << s << endl;
            continue;
        }
        string t;
        t.push_back(s[0]);
        t.push_back(s[1]);
        reverse(s.begin(),s.end());
        s.pop_back();
        s.pop_back();
        ll ans=0;
        if (t=="0b")
        {
            for (ll j = 0; j < s.size(); j++)
            {
                ans+=(s[j]-'0')*two[j];
            }
        }else if (t=="0o")
        {
            for (ll j = 0; j < s.size(); j++)
            {
                ans+=(s[j]-'0')*eight[j];
            }
        }else if (t=="0x")
        {
            for (ll j = 0; j < s.size(); j++)
            {
                if (s[j]>='a'&&s[j]<='f')
                {
                    ll x=10;
                    x+=s[j]-'a';
                    ans+=x*zr[j];
                }else{
                    ans+=(s[j]-'0')*zr[j];
                }
            }
        }else{
            s.push_back(t[1]);
            s.push_back(t[0]);
            reverse(s.begin(),s.end());
            ans=stoll(s);
        }
        cout << ans << endl;
    }
    
}
0