結果
問題 | No.2385 Parse Integer with Radix |
ユーザー |
![]() |
提出日時 | 2023-10-03 02:15:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,181 bytes |
コンパイル時間 | 1,808 ms |
コンパイル使用メモリ | 194,272 KB |
最終ジャッジ日時 | 2025-02-17 04:04:28 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 |
ソースコード
#include <bits/stdc++.h>#include<iostream>#include<map>#include<vector>#include <algorithm>#include<math.h>#include <iomanip>#include<set>#include <numeric>#include<string>using ll = long long;using namespace std;int main(){ll q;cin >> q;for (int i = 0; i < q; i++){string s;cin >> s;ll n = 0, p = 0, mul = 0;if (s.size() <= 2){cout << s << endl;continue;} else if (s[1] == 'b'){p = 2;mul = 2;} else if (s[1] == 'o'){p = 8;mul = 8;} else if (s[1] == 'x'){p = 16;mul = 16;} else {cout << s << endl;continue;}if (s.back() >= '0' && s.back() <= '9') n += (s.back() - '0');else n += ((s.back() - 'a') + 10);s.pop_back();while (s.size() > 2){int num = 0;if (s.back() >= '0' && s.back() <= '9') num += (s.back() - '0');else num += ((s.back() - 'a') + 10);s.pop_back();n += num*p;p *= mul;}cout << n << "\n";}}