結果
| 問題 |
No.2385 Parse Integer with Radix
|
| コンテスト | |
| ユーザー |
forest3
|
| 提出日時 | 2023-09-30 10:21:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 555 bytes |
| コンパイル時間 | 1,660 ms |
| コンパイル使用メモリ | 168,848 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-23 04:28:11 |
| 合計ジャッジ時間 | 2,384 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int Q;
cin >> Q;
for( int i = 0; i < Q; i++ ) {
string s;
cin >> s;
int rad = 10, st = 0, sz = s.size();
if( sz > 2 ) {
string t = s.substr( 0, 2 );
if( t == "0b" ) rad = 2;
else if( t == "0o" ) rad = 8;
else if( t == "0x" ) rad = 16;
}
if( rad != 10 ) st = 2;
long long ans = 0;
for( int i = st; i < sz; i++ ) {
int d = s[i] - '0';
if( rad == 16 ) {
if( isalpha( s[i] ) ) d = s[i] - 'a' + 10;
}
ans = ans * rad + d;
}
cout << ans << endl;
}
}
forest3