結果

問題 No.2385 Parse Integer with Radix
ユーザー cubinglovercubinglover
提出日時 2023-07-21 21:29:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 70,448 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 21:19:41
合計ジャッジ時間 1,202 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
using namespace std;
int main(){
	int q;cin>>q;
	while(q--){
		string s;
		cin>>s;
		if(s.size()==1){
			cout<<s<<endl;
			continue;
		}
		if(s.substr(0,2)=="0b"){
			long long ans=0;
			for(int i=2;i<s.size();++i){
				ans = ans*2+s[i]-'0';
			}
			cout<<ans<<endl;
			continue;
		}
		if(s.substr(0,2)=="0o"){
			long long ans=0;
			for(int i=2;i<s.size();++i){
				ans = ans*8+s[i]-'0';
			}
			cout<<ans<<endl;
			continue;
		}
		if(s.substr(0,2)=="0x"){
			string t="0123456789abcdef";
			long long ans=0;
			for(int i=2;i<s.size();++i){
				for(int j=0;j<16;++j){
					if(t[j]==s[i]){
						ans = ans*16+j;
						break;
					}
				}
			}
			cout<<ans<<endl;
			continue;

		}
		long long ans=0;
		for(int i=0;i<s.size();++i){
			ans = ans*10+s[i]-'0';
		}
		cout<<ans<<endl;
		continue;
	}
}
0