Logic gates
Statement
Goal
A logic gate is an electronic device implementing a boolean function, performing a logical operation on one or more binary inputs and producing a single binary output.Given n input signal names and their respective data, and m output signal names with their respective type of gate and two input signal names, provide m output signal names and their respective data, in the same order as provided in input description.
All type of gates will always have two inputs and one output.
All input signal data always have the same length.
The type of gates are :
AND : performs a logical AND operation.
OR : performs a logical OR operation.
XOR : performs a logical exclusive OR operation.
NAND : performs a logical inverted AND operation.
NOR : performs a logical inverted OR operation.
NXOR : performs a logical inverted exclusive OR operation.
Signals are represented with underscore and minus characters, an undescore matching a low level (0, or false) and a minus matching a high level (1, or true).
Input
Line 1 : n number of input signals.
Line 2 : m number of output signals.
n next lines : two space separated strings : name of input signal, then signal form.
m next lines : four space separated strings : name of output signal, then type of logic gate, then first input name, then second input name.
Line 2 : m number of output signals.
n next lines : two space separated strings : name of input signal, then signal form.
m next lines : four space separated strings : name of output signal, then type of logic gate, then first input name, then second input name.
Output
m lines : two space separated strings : name of output signal, then signal form.
Constraints
1 ≤ n ≤ 4
1 ≤ m ≤ 16
1 ≤ m ≤ 16
Example
Input
2 3 A __---___---___---___---___ B ____---___---___---___---_ C AND A B D OR A B E XOR A B
Output
C ____-_____-_____-_____-___ D __-----_-----_-----_-----_ E __--_--_--_--_--_--_--_--_
Tags
Logic
Difficulty
Easy
Test cases
2 input signals, 3 gates Test
Input
2
3
A __---___---___---___---___
B ____---___---___---___---_
C AND A B
D OR A B
E XOR A B
Output
C ____-_____-_____-_____-___
D __-----_-----_-----_-----_
E __--_--_--_--_--_--_--_--_
2 input signals, 3 gates Validator
Input
2
3
A ____---___---___---___---_
B ___---___---___---___---__
D AND A B
E OR A B
F XOR A B
Output
D ____--____--____--____--__
E ___----__----__----__----_
F ___-__-__-__-__-__-__-__-_
Inverter (NAND) Test
Input
1
1
A __---___---___---___---___
B NAND A A
Output
B --___---___---___---___---
Inverter (NOR) Validator
Input
1
1
A __-_--__---___--__-_-_-_---_____
B NOR A A
Output
B --_-__--___---__--_-_-_-___-----
AND Test
Input
3
3
CLK _-_-_-_-_-_-_-_-_-_-_-_-_-
IN1 ___---___---___---___---__
IN2 --__--__--__--__--__--__--
OUT1 AND CLK IN1
OUT2 AND CLK IN2
OUT3 AND IN1 IN2
Output
OUT1 ___-_-___-_-___-_-___-_-__
OUT2 _-___-___-___-___-___-___-
OUT3 ____--___-______--___-____
AND Validator
Input
3
3
CLK _-_-_-_-_-_-_-_-_-_-_-_-_-
IN1 ----____----____----____--
IN2 --__--__--__--__--__--__--
OUT1 AND CLK IN1
OUT2 AND CLK IN2
OUT3 AND IN1 IN2
Output
OUT1 _-_-_____-_-_____-_-_____-
OUT2 _-___-___-___-___-___-___-
OUT3 --______--______--______--
OR Test
Input
3
3
CLK _-_-_-_-_-_-_-_-_-_-_-_-_-
IN1 ----____----____----____--
IN2 --__--__--__--__--__--__--
OUT1 OR CLK IN1
OUT2 OR CLK IN2
OUT3 OR IN1 IN2
Output
OUT1 ----_-_-----_-_-----_-_---
OUT2 --_---_---_---_---_---_---
OUT3 ------__------__------__--
OR Validator
Input
3
3
CLK _-_-_-_-_-_-_-_-_-_-_-_-_-
IN1 ___---___---___---___---__
IN2 --__--__--__--__--__--__--
OUT1 OR CLK IN1
OUT2 OR CLK IN2
OUT3 OR IN1 IN2
Output
OUT1 _-_---_-_---_-_---_-_---_-
OUT2 --_---_---_---_---_---_---
OUT3 --_---__------_---__------
XOR Test
Input
3
3
CLK _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
IN1 __--__--__--__--__--__--__--__--_
IN2 ___---___---___---___---___---___
OUT1 XOR IN1 CLK
OUT2 XOR IN2 CLK
OUT3 XOR IN2 IN1
Output
OUT1 _--__--__--__--__--__--__--__--__
OUT2 _-__-__-__-__-__-__-__-__-__-__-_
OUT3 __-_----_-____-_----_-____-_----_
XOR Validator
Input
3
3
CLK -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
IN1 ----____----____----____----____-
IN2 ---____----____----____----____--
OUT1 XOR IN1 CLK
OUT2 XOR IN2 CLK
OUT3 XOR IN2 IN1
Output
OUT1 _-_--_-__-_--_-__-_--_-__-_--_-__
OUT2 _-__-_--_-__-_--_-__-_--_-__-_--_
OUT3 ___-___-___-___-___-___-___-___-_
Buffer (OR) Test
Input
1
1
IN0 -_--__---___----____-_--__---___
OUT OR IN0 IN0
Output
OUT -_--__---___----____-_--__---___
Buffer (AND) Validator
Input
1
1
IN0 ---___----____-_-_--__--__---___--_-_--
OUT AND IN0 IN0
Output
OUT ---___----____-_-_--__--__---___--_-_--
NAND Test
Input
3
3
CLK _-_-_-_-_-_-_-_-_-_-_-_-_-
IN1 ___---___---___---___---__
IN2 --__--__--__--__--__--__--
OUT1 NAND CLK IN1
OUT2 NAND CLK IN2
OUT3 NAND IN1 IN2
Output
OUT1 ---_-_---_-_---_-_---_-_--
OUT2 -_---_---_---_---_---_---_
OUT3 ----__---_------__---_----
NAND Validator
Input
3
3
CLK _-_-_-_-_-_-_-_-_-_-_-_-_-
IN1 ----____----____----____--
IN2 --__--__--__--__--__--__--
OUT1 NAND CLK IN1
OUT2 NAND CLK IN2
OUT3 NAND IN1 IN2
Output
OUT1 -_-_-----_-_-----_-_-----_
OUT2 -_---_---_---_---_---_---_
OUT3 __------__------__------__
NOR Test
Input
3
2
IN1 --__--__--__--__--__--__--__--__--__
IN2 ____----____----____----____----____
IN3 --------________--------________----
OUT1 NOR IN2 IN1
OUT2 NOR IN2 IN3
Output
OUT1 __--______--______--______--______--
OUT2 ________----____________----________
NOR Validator
Input
3
2
IN1 -_--__---___----____-----_____-_--__
IN2 __----____----____----____----____--
IN3 ----________--------________--------
OUT1 NOR IN1 IN3
OUT2 NOR IN1 IN2
Output
OUT1 ____--___---_____________---________
OUT2 _-_______-______--_______-_____-____
NXOR Test
Input
4
3
A -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
B --__--__--__--____----____----______------
C -_-__--__--__---___---___---___----____---
D -----_____-----_____-----_____-----_____--
X NXOR A B
Y NXOR B C
Z NXOR C D
Output
X -__--__--__--__-_--_-__-_--_-__-_-_--_-_-_
Y -__-_-_-_-_-_-__--_------_--__-____-___---
Z -_-____--_-__--_---_--______--_--------_--
NXOR Validator
Input
4
3
A ---___---___---___---___---___---___---___
B _-_-_-_-_-_----___---____----____----____-
C ---______------______--------_-_-_-_-_-_--
D --__--__--__--__--__--__--__--__--__--__--
X NXOR A C
Y NXOR B D
Z NXOR B C
Output
X ------______------______---__--_--_--_--__
Y _--__--__--_--_-____-_--_-__-_--_-__-_--_-
Z _-__-_-_--_-------_______-----_-__-_--_-_-
All gates Test
Input
4
16
ZORGLUB ----____----____----____----____----____--
MEGAMAN --____----____----____----____----____----
ZOLTRON ---___---___------______------______-_-_-_
PEW_PEW -_-_-_-_------_____----____---___--__--__-
OUTPUT1 AND ZORGLUB MEGAMAN
OUTPUT2 OR ZORGLUB ZOLTRON
OUTPUT3 XOR ZORGLUB PEW_PEW
OUTPUT4 AND ZORGLUB ZORGLUB
ROGUE_1 OR MEGAMAN MEGAMAN
ROGUE_2 NAND MEGAMAN MEGAMAN
ROGUE_3 NOR PEW_PEW PEW_PEW
ROGUE_4 NXOR PEW_PEW MEGAMAN
SQUAD_1 NAND PEW_PEW MEGAMAN
SQUAD_2 OR ZOLTRON PEW_PEW
SQUAD_3 NOR ZOLTRON PEW_PEW
SQUAD_4 AND ZOLTRON PEW_PEW
MIKADO1 AND MEGAMAN PEW_PEW
MIKADO2 OR MEGAMAN PEW_PEW
MIKADO3 XOR MEGAMAN MEGAMAN
MIKADO4 NXOR ZOLTRON ZOLTRON
Output
OUTPUT1 --______--______--______--______--______--
OUTPUT2 ----__--------------____------__-----_-_--
OUTPUT3 _-_--_-_____--__---_---_---_--__-__-_--_-_
OUTPUT4 ----____----____----____----____----____--
ROGUE_1 --____----____----____----____----____----
ROGUE_2 __----____----____----____----____----____
ROGUE_3 _-_-_-_-______-----____----___---__--__--_
ROGUE_4 -__-_--_--________-___-___-______-_--_-__-
SQUAD_1 _-----_-__------------_----------_----_--_
SQUAD_2 ---_-_------------_----_------___--_---_--
SQUAD_3 ___-_-____________-____-______---__-___-__
SQUAD_4 -_-___-_-___--_____________---________-___
MIKADO1 -_____-_--____________-__________-____-__-
MIKADO2 ---_-_------------_-------_--------__-----
MIKADO3 __________________________________________
MIKADO4 ------------------------------------------
All gates Validator
Input
4
16
A -----_____-----_____-----_____-----_____-----___
B -___---___---___---___---___---___---___---___--
C -_-_-_-_-_-_-_--__--__--__--__--__--__---___---_
D ____----____----____----____----_____-----______
E AND B C
F OR B D
G XOR B A
H AND B A
I OR C C
J NAND C C
K NOR A A
L NXOR A C
M NAND A C
N OR D A
O NOR D A
P AND D A
Q AND C A
R OR C A
S XOR C C
T NXOR D D
Output
E -___-_-___-_-_____-___--______-___--____-_____-_
F -___----__---------_-----___----__---------___--
G _---_--______--_---_--______--_---_--______--_--
H -___-_____---_________---_____-___-_____---_____
I -_-_-_-_-_-_-_--__--__--__--__--__--__---___---_
J _-_-_-_-_-_-_-__--__--__--__--__--__--___---___-
K _____-----_____-----_____-----_____-----_____---
L -_-_--_-_--_-_-_--____--_-__----__-_--__-___-__-
M _-_-_-----_-_-_-------__------__--_-----_---_---
N --------__------____-----___-------__--------___
O ________--______----_____---_______--________---
P ____-_______---_____----______--________--______
Q -_-_-_____-_-_-_______--______--__-_____-___-___
R -----_-_-_------__-------_--__------__---------_
S ________________________________________________
T ------------------------------------------------
Solution language
Solution
Stub generator input