1
answer
0
watching
203
views

C++ PROGRAMMING ARRAYS

 

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.

 

Develop 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.

 

Initial data

6 2

0 1 0 1 1 1

 

Results

1 1 0 1 0 1

The night when it was most lit: 1

The night when it was lit least: 1

 

Explanation

0 1 0 1 1 1 First night

1 1 0 1 0 1 Second night

For unlimited access to Homework Help, a Homework+ subscription is required.

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in

Weekly leaderboard

Start filling in the gaps now
Log in