Back
Close

The Electrician Apprentice

Statement

 Goal

After working with your apprentice Tom on a very bizarre electrical installation, you are about to turn on the power to carry out the final checks. As a professional, you labelled all switches beforehand and made sure they were off before you disconnected the power supply.

However during the intervention, Tom flipped the switches all over the place! Fortunately, you had asked him to take notes, so you should be able to find out which equipment will trigger when the power supply is turned back on.

Switches can be mounted in series or in parallel. For a circuit to be on, all switches in series must be on and at least one switch for each parallel derivation must be on.

Wiring description is a space-delimited sequence of:
• the - character followed by the identifiers of the switches mounted in series
• the = character followed by the identifiers of the switches mounted in parallel
Each SWITCH has a unique label.

Eg. for the following circuit:


                      +-[A1]-+        +-[A4]--[RADIO]---+
| | | |
| +--[A3]--+----------[TV]---+
+--+ | | |
| | | +-----[CONSOLE]---+
| | | |
| +-[A2]-+ |
| |
+------------[POWER SUPPLY]----------+
| |
+--[B1]--[B2]-------------[LIGHTS]---+


The wiring description is:

    TV = A1 A2 - A3
RADIO = A1 A2 - A3 A4
CONSOLE = A1 A2 - A3
LIGHTS - B1 B2
Input
First line: the number of circuits C
Next C lines: name of the EQUIPMENT and wiring description
Next line: the number of Tom's actions A
Next A lines: the SWITCH that Tom toggled
Output
C lines, one for each equipment in the same order.
Each line should read EQUIPMENT is ON or EQUIPMENT is OFF
Constraints
1 ≤ C ≤ 25
0 ≤ A ≤ 25
Length of SWITCH ≤ 20
Length of EQUIPMENT ≤ 40
Max input line length = 1024
Example
Input
1
LIGHT - A1
1
A1
Output
LIGHT is ON

Tags

Difficulty
Easy

Test cases
1 switch 1 light Test
Input
1 LIGHT - A1 1 A1
Output
LIGHT is ON

1 switch 1 light Validator
Input
1 LIGHT - A1 4 A1 A1 A1 A1
Output
LIGHT is OFF

2 parallel switches 1 light Test
Input
1 LIGHT = A1 A2 1 A2
Output
LIGHT is ON

2 parallel switches 1 light Validator
Input
1 LIGHT = A1 A2 3 A2 A1 A2
Output
LIGHT is ON

2 series switches 1 light Test
Input
1 LIGHT - A1 A2 3 A1 A2 A1
Output
LIGHT is OFF

2 series switches 1 light Validator
Input
1 LIGHT - A1 A2 2 A1 A2
Output
LIGHT is ON

Two lights Test
Input
2 LIGHT1 - A1 LIGHT2 - B1 2 A1 B1
Output
LIGHT1 is ON LIGHT2 is ON

Two lights Validator
Input
2 LIGHT1 - A1 LIGHT2 - B1 0
Output
LIGHT1 is OFF LIGHT2 is OFF

Series and parallel Test
Input
1 LIGHT - A1 = A2 A3 6 A1 A1 A2 A2 A3 A1
Output
LIGHT is ON

Series and parallel Validator
Input
1 LIGHT - A1 = A2 A3 - A4 7 A1 A4 A2 A2 A3 A1 A4
Output
LIGHT is OFF

Mixed Test
Input
2 LIGHT1 - A1 = A2 A3 LIGHT2 - B1 = B2 B3 = B4 B5 6 A1 B1 B2 A3 B5 B4
Output
LIGHT1 is ON LIGHT2 is ON

Mixed Validator
Input
2 LIGHT1 - A1 = A2 A3 LIGHT2 - A1 B1 = B2 B3 = B4 B5 7 A1 B1 B2 A3 B5 B4 A1
Output
LIGHT1 is OFF LIGHT2 is OFF

Weird Home Test
Input
6 TV = A1 A2 - A3 BOX = A1 A2 = A3 A4 CONSOLE = A1 A2 LIGHTS = B1 B2 OVEN - KITCHEN = C1 C2 C3 - C4 DISHWASHER - KITCHEN D1 D2 = D3 D4 19 A1 B1 A3 C2 C4 A4 A4 A4 A4 D1 KITCHEN D2 A4 A2 KITCHEN D4 A3 C4 KITCHEN
Output
TV is OFF BOX is ON CONSOLE is ON LIGHTS is ON OVEN is OFF DISHWASHER is ON

Weird Home Validator
Input
6 TV - MAIN = A1 A2 - A3 BOX - MAIN = A1 A2 = A3 A4 CONSOLE - MAIN = A1 A2 LIGHTS - MAIN = B1 B2 OVEN - MAIN KITCHEN = C1 C2 C3 - C4 DISHWASHER - MAIN KITCHEN D1 D2 = D3 D4 21 A1 B1 A3 MAIN C2 C4 A4 A4 A4 A4 D1 KITCHEN D2 A4 A2 KITCHEN D4 A3 C4 MAIN KITCHEN
Output
TV is OFF BOX is OFF CONSOLE is OFF LIGHTS is OFF OVEN is OFF DISHWASHER is OFF

Regular Home Test
Input
24 Room1-Light - Main Room1-Sw-L Room1-Radio - Main Room1-Sw-R Room1-PC - Main Room1-Sw-PC Room2-Light - Main Room2-Sw-L Room2-TV - Main Room2-Sw-TV Room2-Console - Main Room2-Sw-TV Bathroom-Light - Main Bathroom-CB Bathroom-Sw-L Bathroom-Vent - Main Bathroom-CB Bathroom-Sw-L Bathroom-WashingMachine - Main Bathroom-CB Bathroom-ElectricDryer - Main Bathroom-CB Kitchen-Light - Main Kitchen-Sw-L Kitchen-Oven - Main Kitchen-CB1 Kitchen-Sw-O Kitchen-Cooktop - Main Kitchen-CB1 Kitchen-Sw-CT Kitchen-Hood - Main Kitchen-CB1 Kitchen-Sw-CT Kitchen-DishWasher - Main Kitchen-CB1 Kitchen-Sw-CT Kitchen-Fridge - Main Kitchen-CB2 Kitchen-Freezer - Main Kitchen-CB2 InternetBox - Main Living-Light1 - Main Living-Sw-L1 Living-Light2 - Main Living-Sw-L2 Living-TV - Main Living-Sw-TV Living-Console - Main Living-Sw-TV Living-PC - Main Living-Sw-PC Living-Printer - Main Living-Sw-PC 4 Main Bathroom-CB Kitchen-CB1 Kitchen-CB2
Output
Room1-Light is OFF Room1-Radio is OFF Room1-PC is OFF Room2-Light is OFF Room2-TV is OFF Room2-Console is OFF Bathroom-Light is OFF Bathroom-Vent is OFF Bathroom-WashingMachine is ON Bathroom-ElectricDryer is ON Kitchen-Light is OFF Kitchen-Oven is OFF Kitchen-Cooktop is OFF Kitchen-Hood is OFF Kitchen-DishWasher is OFF Kitchen-Fridge is ON Kitchen-Freezer is ON InternetBox is ON Living-Light1 is OFF Living-Light2 is OFF Living-TV is OFF Living-Console is OFF Living-PC is OFF Living-Printer is OFF

Regular Home Validator
Input
23 Room1-Light - Main Room1-Sw-L Room1-Radio - Main Room1-Sw-R Room1-PC - Main Room1-Sw-PC Room2-Light - Main Room2-Sw-L Room2-TV - Main Room2-Sw-TV Room2-Console - Main Room2-Sw-TV Bathroom-Light - Main Bathroom-CB Bathroom-Sw-L Bathroom-Vent - Main Bathroom-CB Bathroom-Sw-L Bathroom-WashingMachine - Main Bathroom-CB Bathroom-ElectricDryer - Main Bathroom-CB Kitchen-Light - Main Kitchen-Sw-L Kitchen-Oven - Main Kitchen-CB1 Kitchen-Sw-O Kitchen-Cooktop - Main Kitchen-CB1 Kitchen-Sw-CT Kitchen-Hood - Main Kitchen-CB1 Kitchen-Sw-CT Kitchen-Fridge - Main Kitchen-CB2 Kitchen-Freezer - Main Kitchen-CB2 InternetBox - Main Living-Light1 - Main Living-Sw-L1 Living-Light2 - Main Living-Sw-L2 Living-TV - Main Living-Sw-TV Living-Console - Main Living-Sw-TV Living-PC - Main Living-Sw-PC Living-Printer - Main Living-Sw-PC 6 Bathroom-CB Kitchen-CB1 Kitchen-CB2 Main Living-Sw-L2 Living-Sw-PC
Output
Room1-Light is OFF Room1-Radio is OFF Room1-PC is OFF Room2-Light is OFF Room2-TV is OFF Room2-Console is OFF Bathroom-Light is OFF Bathroom-Vent is OFF Bathroom-WashingMachine is ON Bathroom-ElectricDryer is ON Kitchen-Light is OFF Kitchen-Oven is OFF Kitchen-Cooktop is OFF Kitchen-Hood is OFF Kitchen-Fridge is ON Kitchen-Freezer is ON InternetBox is ON Living-Light1 is OFF Living-Light2 is ON Living-TV is OFF Living-Console is OFF Living-PC is ON Living-Printer is ON

Solution language

Solution

Stub generator input