結果
問題 | No.2385 Parse Integer with Radix |
ユーザー |
![]() |
提出日時 | 2023-07-21 21:32:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 1,060 bytes |
コンパイル時間 | 2,250 ms |
コンパイル使用メモリ | 197,288 KB |
最終ジャッジ日時 | 2025-02-15 16:24:23 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 |
ソースコード
#include<bits/stdc++.h>using namespace std;typedef long long int ll;typedef unsigned long long ull;typedef long double ld;int dx[8]={1,0,-1,0,1,1,-1,-1},dy[8]={0,1,0,-1,1,-1,1,-1};const long long mod = 998244353;const ll inf = 1LL<<60;const int INF = 1e9+1;string solve(string s){ull n=0;ull pos = 1;if(s[0]=='0' and s[1]=='b'){for(int i=(int)s.size()-1;i>1;i--){n += pos*(s[i]-'0');pos *= 2;}return to_string(n);}else if(s[0]=='0' and s[1]=='o'){for(int i=(int)s.size()-1;i>1;i--){n += pos*(s[i]-'0');pos *= 8;}return to_string(n);}else if(s[0]=='0' and s[1]=='x'){for(int i=(int)s.size()-1;i>1;i--){if('0'<=s[i] and s[i]<='9')n += pos*(s[i]-'0');else n += pos*(s[i]-'a'+10);pos *= 16;}return to_string(n);}else return s;}int main(){int q;cin >> q;while(q--){string s;cin >> s;cout << solve(s) << endl;}}