結果
| 問題 |
No.2385 Parse Integer with Radix
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-21 21:33:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,435 bytes |
| コンパイル時間 | 1,666 ms |
| コンパイル使用メモリ | 167,316 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-21 22:52:43 |
| 合計ジャッジ時間 | 2,226 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 |
ソースコード
// Problem: No.2385 Parse Integer with RadixNo.2385 用基数解析整数
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2385
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
ll ksm(ll n,ll p,int mod){
int ans=1;
while(p){
if(p&1) ans=(ans*n)%mod;
n=(n*n)%mod;p>>=1;
}
return ans;
}
ll inv(ll b,ll c=mod) {return ksm(b,c-2,c);}
class Num{
public:
ll num;
Num(ll x) {num=(x%mod+mod)%mod;}
Num operator+(Num p) {return Num(num+p.num);}
Num operator-(Num p) {return Num(num-p.num);}
Num operator*(Num p) {return Num(num*p.num);}
Num operator/(Num p) {return Num(num*inv(p.num));}
Num operator=(Num p) {this->num=p.num;return *this;}
friend ll get(Num p) {return p.num;}
};
void solve() {
string s;
cin>>s;
if(s.size()==1||s[1]>='0'&&s[1]<='9') {
cout<<s<<endl;
return ;
}
ll ans=0,p=1;
for(int i=s.size()-1;i>=2;i--) {
if(s[1]=='b') {
ans+=(s[i]-'0')*p;
p=p*2;
}
else if(s[1]=='o') {
ans+=(s[i]-'0')*p;
p=p*8;
}
else {
if(s[i]>='0'&&s[i]<='9') ans+=(s[i]-'0')*p;
else ans+=(s[i]-'a'+10)*p;
p=p*16;
}
}
cout<<ans<<endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T=1;
cin>>T;
while(T--) {
solve();
}
return 0;
}