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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question

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.

Create 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

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr