#P5777. Logic Decoder Circuit Simulation

    ID: 19005 Type: Default 1000ms 256MiB

Logic Decoder Circuit Simulation

Logic Decoder Circuit Simulation

Professor W, teaching the course Digital Logic at T University, has assigned an experiment to design and implement a logic decoder circuit with four inputs and four outputs. The circuit must satisfy the following constraints:

  1. Only 2-input, 1-output gate circuits (with specified types and numbers) may be used as building components.
  2. The connection scheme must use the fewest possible gate circuits.

In digital logic, every signal takes one of two values: high (denoted by 11) or low (denoted by 00). Each gate circuit is characterized uniquely by its truth table, which maps the input values to the output value(s). For example, an AND gate with inputs XX and YY has the following truth table:

$$\begin{array}{ccc} X & Y & S \\ 0 & 0 & 0 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \\ 1 & 1 & 1 \end{array} $$

When connecting circuits, note that a gate’s output may feed several other gates’ inputs while each gate input can only be connected to one output. Signal transmission is strictly unidirectional; an output cannot (directly or indirectly) feed back into the same gate’s input.

For this problem, you are given the truth table of a 4-input, 4-output decoder. There are exactly 1616 rows describing every possible input combination and its corresponding output. Your task is to simulate such a decoder. In other words, after reading the truth table, your program will answer several queries. Each query gives a 4-bit input and you must output the corresponding 4-bit output as defined in the provided truth table.

Note: All formulas are given in LaTeX format.

inputFormat

The input consists of several parts:

  1. Truth Table: The first 16 lines each contain 8 space-separated integers (each either 0 or 1). In each line, the first four numbers represent a unique 4-bit input combination (in lexicographical order) and the next four numbers represent its corresponding 4-bit output.

  2. Queries: The next line contains a single integer QQ (1Q10001 \le Q \le 1000), the number of queries. Each of the following QQ lines contains 4 space-separated integers (each either 0 or 1) representing a 4-bit input signal.

You can assume that the truth table covers all 16 possible input combinations and that every query input will exactly match one of the truth table entries.

outputFormat

For each query, output a single line with 4 space-separated integers representing the corresponding output as defined by the truth table.

sample

0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 0
0 0 1 1 0 0 1 1
0 1 0 0 0 1 0 0
0 1 0 1 0 1 0 1
0 1 1 0 0 1 1 0
0 1 1 1 0 1 1 1
1 0 0 0 1 0 0 0
1 0 0 1 1 0 0 1
1 0 1 0 1 0 1 0
1 0 1 1 1 0 1 1
1 1 0 0 1 1 0 0
1 1 0 1 1 1 0 1
1 1 1 0 1 1 1 0
1 1 1 1 1 1 1 1
3
0 0 0 0
1 0 1 0
1 1 1 1
0 0 0 0

1 0 1 0 1 1 1 1

</p>