結果

問題 No.2385 Parse Integer with Radix
ユーザー pengin_2000pengin_2000
提出日時 2023-07-21 21:29:06
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 1,081 ms
コンパイル使用メモリ 29,176 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 21:18:32
合計ジャッジ時間 1,438 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
long long int d(char c)
{
	if ('0' <= c && c <= '9')
		return c - '0';
	else
		return c - 'a' + 10;
}
long long int f(char s[], long long int i, long long int p)
{
	long long int res = 0;
	for (; s[i] != '\0'; i++)
		res = p * res + d(s[i]);
	return res;
}
char s[102];
void solve()
{
	scanf("%s", s);
	long long int ans;
	if (s[1] == 'b')
		ans = f(s, 2, 2);
	else if (s[1] == 'o')
		ans = f(s, 2, 8);
	else if (s[1] == 'x')
		ans = f(s, 2, 16);
	else
		ans = f(s, 0, 10);
	printf("%lld\n", ans);
}
int main()
{
	int q;
	scanf("%d", &q);
	for (; q > 0; q--)
		solve();
	return 0;
}
0