I need some help with a C++ arrays task. (Please make it work as like image provded!)
I need some help with a C++ arrays task. (Please make it work as like image provded!)
2. Lights
The park is illuminated by n (1 <n <100) lights. Each of them shines all night or not. Of course, which lights were on the first night and which were not. Every other night the condition of the lamps shall be determined by the following rules:
the lamp will not illuminate if both of its neighbors were lit last night;
the lamp shall illuminate if one of its neighbors was illuminated last night and the other was not;
if neither of the first two rules applies to the lamp, it will illuminate when the night is even and will not illuminate when the night is odd.
Make a program to determine which lights are on and which will not be lit when k (1 <k <100) nights have elapsed, and to find which night the most lights were lit and which the least. If there are several identical nights with the most or least lights lit, the night with the lower number must be indicated.
The first line of the original data file contains two integers: the number of lights n and the number of nights k. The second line contains a sequence of zeros and units separated by a space. This is the state of each lamp: a unit means that the lamp was lit on the first night, and zero means that it was not lit.
Step by step
Solved in 5 steps