結果
問題 | No.2385 Parse Integer with Radix |
ユーザー | PAKACHU |
提出日時 | 2023-07-21 21:32:17 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,060 bytes |
コンパイル時間 | 2,565 ms |
コンパイル使用メモリ | 203,912 KB |
実行使用メモリ | 4,348 KB |
最終ジャッジ日時 | 2023-10-21 21:22:32 |
合計ジャッジ時間 | 2,849 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge9 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 2 ms
4,348 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 2 ms
4,348 KB |
ソースコード
#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; } }