結果

問題 No.2385 Parse Integer with Radix
ユーザー YwestbuilderkYwestbuilderk
提出日時 2024-01-24 19:38:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 2,394 ms
コンパイル使用メモリ 202,288 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-24 19:38:21
合計ジャッジ時間 3,394 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	int q;
	cin >> q;
	for(int i = 0;i < q;i++){
		string s;
		cin >> s;
		if((int)s.size() == 1) cout << s[0] << endl;
		else{
			int ans = 0;
			if(s[0] == '0' and s[1] == 'b'){
				for(int i = 2;i < (int)s.size();i++){
					ans *= 2;
					ans += s[i] - '0';
				}
			}
			else if(s[0] == '0' and s[1] == 'o'){
				for(int i = 2;i < (int)s.size();i++){
					ans *= 8;
					ans += s[i] - '0';
				}
			}
			else if(s[0] == '0' and s[1] == 'x'){
				for(int i = 2;i < (int)s.size();i++){
					ans *= 16;
					if('0' <= s[i] and s[i] <= '9') ans += s[i] - '0';
					else{
					  int t = s[i] - 'a' + 10;
					  ans += t;
					}
				}
			}
			else{
				for(int i = 0;i < (int)s.size();i++){
					ans *= 10;
					ans += s[i] - '0';
				}
			}
			cout << ans << endl;
		}
	}
}
0