Question Mr. Woods, an electrician for Timberland city, has made some faulty connections on eight street lights. The errors cause a street light to
Question Mr. Woods, an electrician for Timberland city, has made some faulty connections on eight street lights. The errors cause a street light to go OFF if the street lights adjacent to that light were both ON (represented as 1) or both OFF (represented as 0) on the previous night. Otherwise, the light will go ON as normal. The two street lights at the end of the road have only a single adjacent street light, so the light at the end can be assumed to be always OFF. The state of the lights on a particular day is considered for the following day, not for the same day. Because of this fault, people are having difficulty driving on the road at night. They have filed a complaint to the Head of the Federal Highway Administration. Based on this complaint the head has ordered a report of the state of street lights after M days. Write an algorithm to output the state of the street lights after the given M days. Input The first line of input consists of an 1 2 3 4560 a 7 8 GENHENGGANZHON 10 9 { 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 import java.util.*; import java.lang.*; import java.io.*; 28 29 30 31 32 33 /* */ public class Solution public static int[ { } int[] answer: // Write your return answer; public static void { Scanner in = new //input for cur int currentState int currentState for(int idx = 0; { currentState } // input for day int days = in.nex intll result ct Question Input The first line of input consists of an integer- currentState_size, representing the number of street lights (N). The next line consists of N space- separated integers- currentState, representing the current state of the street lights (i.e. either 0 or 1). The last line consists of an integer - days, representing the number of days (M). Output Print eight space-separated integers representing the state of the street lights after M days. Constraints 1 days 106 Example Input: 8 11101111 2 Output: 00000110 Explanation: The street light at position 0 has as neighboring street lights 0 O APR 30 1 2 3 4 5678 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 23 import java.util.*; import java.lang.*; import java.io.*; /* * */ public class Solution { public static int [] { } int[] answer = new int [100]; // Write your code here I return answer; street Light (int public static void main(String[] args { Scanner in = new Scanner(System.i //input for currentState int currentState_size = in.nextInt int currentState[] = new int [curre for(int idx = 0; idx < currentSta { currentState [idx] = in.nextInt } // input for days int days = in.nextInt(); intil recult = ctreetlight (currents 30 7d 123 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 22 import java.util.*; import java.lang.*; import java.io.*; /* * */ public class Solution { public static int [] streetLight (int[] current State, int days) { } int[] answer = new int [100]; // Write your code here I return answer; public static void main(String[] args) { Scanner in = new Scanner(System.in); //input for currentState 57:52 int currentState_size = in.nextInt(); int currentState[] = new int [current State_size]; for(int idx = 0; idx < currentState_size; idx++) { currentState [idx] = in.nextInt (); } // input for days int days = in.nextInt (); int [1 recult - streetlight(current state davel. ^
Step by Step Solution
There are 3 Steps involved in it
Step: 1
It looks like youve been given a task to complete a Java program that simulates the behavior of street lights under a specific set of rules for a give...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started