eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Decoding EDSAC Data

Decoding EDSAC Data

The world's first full-scale, stored-program, electronic, digital computer was the EDSAC (Electronic Delay Storage Automatic Calculator). The EDSAC had an accumulator-based instruction set, operating on \textbf{17}-bit words (and \textbf{35}-bit double words), and used a \textbf{5}-bit teletypewriter code for input and output. The EDSAC was programmed using a very simple assembly language: a single letter opcode followed by an unsigned decimal address, followed by the the letter "\textbf{F}" (for full word) or "\textbf{D}" (for double word). For example, the instruction "\textbf{A 128 F}" would mean "\textbf{add the full word at location 128 to the accumulator}", and would be assembled into the \textbf{17}-bit binary value \textbf{11100000100000000}, consisting of a \textbf{5}-bit opcode (\textbf{11100}="\textbf{add}"), an \textbf{11}-bit operand (\textbf{00010000000 = 128}), and a single \textbf{0} bit denoting a full word operation(a \textbf{1} bit would indicate a double word operation). Although arithmetic on the EDSAC was fixed point two's complement binary, it was not mere intger arithmetic (as is common with modern machines). The EDSAC hardware assumed a binary point between the lrftmost bit and its immediate successor. Thus the hardware could handle only values in the range \textbf{-1.0} ≤ \textbf{x} < \textbf{1.0}. For example: As you can see, the largest possible positive value was: \textbf{01111111111111111 = 0.9999847412109375} and the smallest possible positive value was: \textbf{00000000000000001 = 2^\{-16\} = 0.0000152587890625} (This also happens to be the increment between successive values on the EDSAC). By a curious coincidence(or an elegant design decision), the opcode for the add operation (\textbf{11100}) was the same as the teleprinter code for the letter "\textbf{A}". The opcode for subtract was the same as the teleprinter code for "\textbf{S}" (\textbf{01100}), and so on. This simplified the programming for the assembler (which, incidentally, was a mere \textbf{31} instructions long). The EDSAC teleprinter alphabet was "\textbf{PQWERTYUIOJ#SZK*?F@D!HNM&LXGABCV}" (with "\textbf{P}"=\textbf{00000}, "\textbf{Q}"=\textbf{00001}, and so on, up to "\textbf{V}"=\textbf{11111}). UNfortunately, the EDSAC assembler had no special directives for data values. On the other hand, there was no reason that ordinary instructions couldn't be used for this, thus, an EDSAC programmer desiring to reserve space for the constant \textbf{3/4} (represented as \textbf{01100000000000000}) would use the instruction "\textbf{S O F}" and for \textbf{1/3} (which is approximately represented as \textbf{00101010101010101}) "\textbf{T 682 D}", and so on. Your job is to write a program that will translate EDSAC instructions into the appropriate decimal fractions. \InputFile The first line of input contains a single integer \textbf{P} (\textbf{1} ≤ \textbf{P} ≤ \textbf{1000} ) which is the number of data sets that follow. Each data set is a single line that contains \textbf{N} (the dataset number), followed by a space, followed by an EDSAC instruction of the form: \textbf{c d s}, where \textbf{c} is a single character in the EDSAC alphabet, \textbf{d} is an unsigned decimal number (\textbf{0} ≤ \textbf{d} < \textbf{2^11}), and \textbf{s} is either a '\textbf{D}' or '\textbf{F}'. \OutputFile For each data set there is one line of output. It contains the data set number (\textbf{N}) followed by a single space, followed by the exact decimal fraction represented by the by the EDSAC instruction, including a minus sign (for negative values). The format for the decimal fraction is: \textbf{sb.ddd...}, where \textbf{s} is an optional minus sign, \textbf{b} is either a \textbf{1} or \textbf{0}, and \textbf{d} is any decimal digit (\textbf{0-9}). There must be at least \textbf{1} and at most \textbf{16} digits after the decimal point. Trailing zeros in the fraction must be suppressed.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
13
1 P 0 F
2 I 0 F
3 & 0 F
4 ? 0 F
5 Q 1228 D
6 P 0 D
7 V 2047 D
8 * 2047 D
9 ? 0 D
10 P 256 F
11 V 1536 F
12 T 682 D
13 T 54 F
Вихідні дані #1
1 0.0
2 0.5
3 -0.5
4 -1.0
5 0.0999908447265625
6 0.0000152587890625
7 -0.0000152587890625
8 0.9999847412109375
9 -0.9999847412109375
10 0.0078125
11 -0.015625
12 0.3333282470703125
13 0.31414794921875
Джерело 2011 Greater New York Regional