結果
問題 | No.2385 Parse Integer with Radix |
ユーザー |
|
提出日時 | 2023-07-27 22:12:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 967 bytes |
コンパイル時間 | 1,405 ms |
コンパイル使用メモリ | 169,932 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-05 01:17:48 |
合計ジャッジ時間 | 2,047 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 |
ソースコード
#include <bits/stdc++.h>using namespace std;long long convert(string s, int mul){long long a = 0;long long b = 1;for (int i = 0; i < s.size(); i++){if (s[s.size() - i - 1] >= 'a' && s[s.size() - i - 1] <= 'f'){a += b * (10 + s[s.size() - i - 1] - 'a');}else{a += b * (s[s.size() - i - 1] - '0');}b *= mul;}// cout << a << endl;return a;}int main(){int Q;cin >> Q;vector<string> S(Q);for (int i = 0; i < Q; i++){cin >> S[i];}for (int i = 0; i < Q; i++){if (S[i].size() < 2){cout << S[i] << endl;continue;}string header = S[i].substr(0, 2);string num = S[i].substr(2);// cout << header << endl;long long ans;if (header == "0b"){ans = convert(num, 2);}else if (header == "0o"){ans = convert(num, 8);}else if (header == "0x"){ans = convert(num, 16);}else{cout << S[i] << endl;continue;}cout << ans << endl;}}