結果
| 問題 |
No.2385 Parse Integer with Radix
|
| コンテスト | |
| ユーザー |
hiro71687k
|
| 提出日時 | 2023-07-23 21:17:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,835 bytes |
| コンパイル時間 | 3,868 ms |
| コンパイル使用メモリ | 253,120 KB |
| 最終ジャッジ日時 | 2025-02-15 18:37:42 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 |
ソースコード
#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;
}
}
hiro71687k