Title: There are 100 lamps, numbered 1~100, respectively corresponding to 100 switch control. Start all facing up (means open, facing down), and then do the following: the reverse direction of a multiple of number 1, the reverse direction of the number of multiples of 2, and the reverse direction of a multiple of 3 is numbered. A switch is dialed in the opposite direction with the number 100, and the number of the lamp that was last turned off.
Here's My Code
BOOL[] Light =New BOOL[ -]; for(inti =0; I < -; i++) Light[i]=true;//all lights are in the initial state of open for(inti =0; I < -; i++) for(intj =0; J < -; J + +) if(j +1)% (i +1) ==0)//If the number is a multiple of nLIGHT[J] = light[j] = =false?true:false;//Reverse Dial Switch for(inti =0; I < -; i++) if(Light[i] = =false) Console.WriteLine ("Section"+ (i +1) +"number lights are off");
Here's the heartbreaking code of a great God.
for (int1; I <= sqrt ( "First" " lights are off " << Endl;
Study it!
Algorithm problem-hundred lights to extinguish