結果
問題 | No.2385 Parse Integer with Radix |
ユーザー |
|
提出日時 | 2023-11-22 18:53:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,275 bytes |
コンパイル時間 | 2,444 ms |
コンパイル使用メモリ | 207,592 KB |
最終ジャッジ日時 | 2025-02-17 23:04:22 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 |
ソースコード
#include<bits/stdc++.h>using namespace std;using ll=long long;ll p(ll a,ll n){ll res=1;while(n--){res*=a;}return res;}int main(){set<char> alp;alp.insert('a');alp.insert('b');alp.insert('c');alp.insert('d');alp.insert('e');alp.insert('f');map<char,ll> tra;tra['a']=10;tra['b']=11;tra['c']=12;tra['d']=13;tra['e']=14;tra['f']=15;ll q;cin>>q;while(q--){string s;cin>>s;ll n=s.size();ll ans=0;if(s[1]=='b'){reverse(s.begin(),s.end());s.pop_back();s.pop_back();n-=2;for(ll i=0;i<n;i++){ans+=(s[i]-'0')*p(2,i);}cout<<ans<<endl;}else if(s[1]=='o'){reverse(s.begin(),s.end());s.pop_back();s.pop_back();n-=2;for(ll i=0;i<n;i++){ans+=(s[i]-'0')*p(8,i);}cout<<ans<<endl;}else if(s[1]=='x'){reverse(s.begin(),s.end());s.pop_back();s.pop_back();n-=2;for(ll i=0;i<n;i++){if(alp.find(s[i])!=alp.end()){ans+=tra[s[i]]*p(16,i);}else{ans+=(s[i]-'0')*p(16,i);}}cout<<ans<<endl;}else if(s.size()<=2){cout<<s<<endl;}else{cout<<s<<endl;}}}