結果
問題 | No.2385 Parse Integer with Radix |
ユーザー |
|
提出日時 | 2024-03-18 11:42:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,282 bytes |
コンパイル時間 | 4,517 ms |
コンパイル使用メモリ | 259,092 KB |
最終ジャッジ日時 | 2025-02-20 07:14:10 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using namespace atcoder;using ll = long long;int main() {int Q; cin >> Q;while (Q--) {string S; cin >> S;int N = S.size();if (N > 2 && S.substr(0, 2) == "0b") {string S1 = S.substr(2);reverse(S1.begin(), S1.end());ll p = 1, ans = 0;for (int i = 0; i < S1.size(); i++) {ans += p * (S1[i] - '0');p *= 2;}cout << ans << endl;} else if (N > 2 && S.substr(0, 2) == "0o") {string S1 = S.substr(2);reverse(S1.begin(), S1.end());ll p = 1, ans = 0;for (int i = 0; i < S1.size(); i++) {ans += p * (S1[i] - '0');p *= 8;}cout << ans << endl;} else if (N > 2 && S.substr(0, 2) == "0x") {map<char, int> mp = { {'0', 0}, {'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, {'6', 6}, {'7', 7},{'8', 8}, {'9', 9}, {'a', 10}, {'b', 11}, {'c', 12}, {'d', 13}, {'e', 14}, {'f', 15}};string S1 = S.substr(2);reverse(S1.begin(), S1.end());ll p = 1, ans = 0;for (int i = 0; i < S1.size(); i++) {ans += p * mp[S1[i]];p *= 16;}cout << ans << endl;} else {cout << S << endl;}}return 0;}