Hello dear...
Here is the C program for the given problem statement. The logic is too simple. It was given that, each two neighbouring lights will have different state(on/off).
So, if the first light state is off(0) then he can switch off all N lights in N seconds.
Else if the first light is on(1) then he have to waste 1 extra second to turn off both light and timer for all N lights. So total time will be 2*N seconds.
Thats it. Here is the C program. I have also written comments for better understanding. Also attached images of output and code for your comfort.
main.c
#include <stdio.h>
//main method
int main() {
//declare required variables
int T,N,i,j;
//take input for no. of test cases
scanf("%d", &T);
//run loop for T times
for(i=0; i<T; i++){
//take input for number of lights
scanf("%d", &N);
//create array to store states of N lights
int states[N];
//take states of all N lights as input
for(j=0; j<N; j++){
scanf("%d", &states[j]);
}
//if first lamp is on
if(states[0]==0)
//print N seconds for given test case
printf("Case %d: %ds\n", i+1, N);
else
//print N*2 seconds for given test case
printf("Case %d: %ds\n", i+1, N*2);
}
//end
return 0;
}
input:
Output:
image of code:
Hope you like it.
If you like my work please give me a like and feedback. That helps me a lot. Thank you.
All the best.
write in C language Decoration Lights Jojo is currently working in an office as a security....
Write in C language . Thank you Count Sheep Jojo is having problem to sleep at night. He can't fall asleep and it makes him feel tired every day. Having this problem, Jojo told his friend Bibi, and Bibi advised him to do sheep counting while he tries to sleep. Jojo decided to try using this trick for N nights, to test its effectiveness. Jojo realized that he would fall asleep if he imagined a total of 10 white sheep....
C Programming Language Problem Title: Discount Jojo is browsing the internet while suddenly he sees an ad about the new cafe. The promotion is if the price of an item is N dollars, then you can buy the second item for half the price, the third item for a quarter of the original price, and so on, but if it becomes less than M dollars, then you have to pay M dollars. He wonders how much he has to pay...
C language Thank you Jojo is going to a restaurant. There are N foods listed in the menu, and the items are sorted increasingly based on its price. Now Jojo is wondering how many foods are there with price P. As the number of food in the menu can be a lot, Jojo will need your help to answer his questions. Jojo knows you can count really fast, so he will give you M questions. Format Input Input begins with...
Write in C language CEO's Problem Every CEO has their own unique problem, they say. The same goes to Jajo. Determining the fate of his newbom company is super tough. Every year, las board committee present him with S denoting the number of customers that use his company's services out of total M customers already in the market. And every year, C number of new customers will enter the market, and all of them will use his company's services Other...
This new company wants to target a new market: genetic engineering for home and office decoration. Here's their plan: they want you to create a bacterial culture that will not only fluoresce in dim light, but also fluoresce in an oscillatory manner. Given your experience with operons, you decide that you'd probably start there... Here's one hint: to make cells fluoresce, you can make them express a protein called Green Fluorescent Protein (or GFP). This protein is not naturally produced...
Convert the following C fragment to equivalent MIPS assembly language Write mini calculator that take two integer numbers as input and ask the user if he need to compute addition, subtraction, remainder, division, or multiplication then print the result. Hint: you can give each operation a special number. For example, the addition (1), subtraction (2), …. And so on. The output must be something like: Enter the first integer number: 5 Enter the second integer number: 3 Which operation? 1...
write the solution of the program by python 3 language : I need the program using list : A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time...
THIS IS A PLC PROGRAM CALLED SIMATIC MANGER. WE NEED TO WRITE LADDER LOGIC PROGRAM AND FORM A SYMBOL TABLE We were unable to transcribe this imageThe painting turn-table system shown in the following figure has a DC motor, two limit switches, a pneumatic cylinder, a start button and two spray guns. The paint guns are activated by 24 V DC voltage. The motor turns the table only in one direction Red Spray gun Blue spray gun Limit switch trigger...
Write and submit one complete Java program to solve the following requirements. Your program will employ packages (that is, source directories), and contain multiple source files. Because you are using packages, your code should be in a directory named “Greenhouse.” You should be able to compile your code using the command “javac Greenhouse\*.java” from a directory just below the Greenhouse directory. In the program for this assignment, class names have been specified. You mustuse the supplied class name for both...
In this lab, you will design a finite state machine to control the tail lights of an unsual car. There are three lights on each side that operate in sequence to indicate thedirection of a turn. Figure ! shows the tail lights and Figure 2 shows the flashing sequence for (a) left turns and (b) right rums. ZOTTAS Figure 28:8: BCECECece BCECECECes BCECECECB BCECECBCB 8888 Figure 2 Part 1 - FSM Design Start with designing the state transition diagram for...