結果
| 問題 |
No.2385 Parse Integer with Radix
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-21 21:54:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 964 bytes |
| コンパイル時間 | 875 ms |
| コンパイル使用メモリ | 89,468 KB |
| 最終ジャッジ日時 | 2025-02-15 16:48:54 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 |
ソースコード
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<tuple>
using namespace std;
typedef long long ll;
ll f(string s,int base){
int n=s.size();
ll res=0;
for(int i=0;i<n;i++){
res*=base;
if(base==16 && 'a'<=s[i] && s[i]<='f'){
res+=(int)(s[i]-'a'+10);
}else{
res+=(int)(s[i]-'0');
}
}
return res;
}
int main(){
int Q;
cin>>Q;
vector<ll> output;
for(int q=0;q<Q;q++){
string S;
cin>>S;
ll ans=0;
string s=S.substr(0,2);
if(s=="0b"){
ans=f(S.substr(2),2);
}else if(s=="0o"){
ans=f(S.substr(2),8);
}else if(s=="0x"){
ans=f(S.substr(2),16);
}else{
ans=f(S,10);
}
output.push_back(ans);
//cout<<ans<<endl;
}
for(ll v:output){
cout<<v<<endl;
}
}