No.2385 Parse Integer with Radix
タグ : / 解いたユーザー数 220
作問者 :
cleantted
tatyam
PCTprobability
👑
amentorimaru
Problem Statement
You are going to write a program that processes a non-negative integer represented in one of the formats base $2$, base $8$, base $10$, or base $16$, and converts it to a base $10$ number.
You are given $Q$ queries.
In the $i$-th query, you are given a string $S_i$ representing a non-negative integer $N_i$. Output $N_i$ in base $10$. The string $S_i$ is given in one of the following formats.
- For base $2$: $S_i$ starts with "
0b", followed by the representation of $N_i$ in base $2$ using the characters {0,1}. - For base $8$: $S_i$ starts with "
0o", followed by the representation of $N_i$ in base $8$ using the characters {0,1,2,3,4,5,6,7}. - For base $10$: $S_i$ is the representation of $N_i$ in base $10$ using the characters {
0,1,2,3,4,5,6,7,8,9}. -
For base $16$: $S_i$ starts with "
0x", followed by the representation of $N_i$ in base $16$ using the characters {0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f}.
The base $16$ digits {0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f} represent, in base $10$, $\lbrace 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 \rbrace$, respectively.
Note that the answer may not fit in a $32$ bit integer type.
Constraints
- $1\leq Q\leq 100$
- $0\leq N_i\leq 10^{18}$
- $Q,N_i$ are integers
-
$S_i$ is a string consisting of digits and lowercase English letters that represents the integer $N_i$ in one of base $2$, base $8$, base $10$, or base $16$
- For base $2$: $S_i$ starts with
0b, and the rest is a string of at least $1$ character consisting of the characters {0,1} - For base $8$: $S_i$ starts with
0o, and the rest is a string of at least $1$ character consisting of the characters {0,1,2,3,4,5,6,7} - For base $16$: $S_i$ starts with
0x, and the rest is a string of at least $1$ character consisting of the characters {0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f} - For base $10$: $S_i$ does not start with any of
0b,0o,0x, and is a string of at least $1$ character consisting of the characters {0,1,2,3,4,5,6,7,8,9} - If $N_i=0$ and the base is $2$: $S_i$ is
0b0 - If $N_i=0$ and the base is $8$: $S_i$ is
0o0 - If $N_i=0$ and the base is $10$: $S_i$ is
0 - If $N_i=0$ and the base is $16$: $S_i$ is
0x0 - If $N_i\ne 0$ and the base is $2$: $S_i$ never starts with
0b0 - If $N_i\ne 0$ and the base is $8$: $S_i$ never starts with
0o0 - If $N_i\ne 0$ and the base is $10$: $S_i$ never starts with
0 - If $N_i\ne 0$ and the base is $16$: $S_i$ never starts with
0x0
- For base $2$: $S_i$ starts with
Input
$Q$ $S_1$ $S_2$ $S_3$ $\ \vdots$ $S_Q$
The first line contains the number of queries $Q$ of the input case, and each of the following $Q$ lines contains a string $S_i$ representing an integer $N_i$.
Output
$N_1$ $N_2$ $N_3$ $\ \vdots$ $N_Q$
Output $Q$ lines. On line $i\ (1 \le i \le Q)$, output the non-negative integer $N_i$ represented by $S_i$ in base $10$.
Sample
Sample 1
Input
24 0b0 0o0 0 0x0 0b1 0o1 1 0x1 0b1010 0o12 10 0xa 0b110110110100110110100101110100110001100001111001101001110 0o6664664564614171516 123456789012345678 0x1b69b4ba630f34e 0b110111100000101101101011001110100111011000111111111111111111 0o67405553164730777777 999999999999999999 0xde0b6b3a763ffff 0b110111100000101101101011001110100111011001000000000000000000 0o67405553164731000000 1000000000000000000 0xde0b6b3a7640000
Output
0 0 0 0 1 1 1 1 10 10 10 10 123456789012345678 123456789012345678 123456789012345678 123456789012345678 999999999999999999 999999999999999999 999999999999999999 999999999999999999 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。