IBM classic interview questions

xiaoxiao2021-03-06  39

There are 50 people in the village, and each person has a dog, there is a disease in these 50 dogs (this disease is not infected), so people want to find a sick dog. Everyone can observe other 49 dogs to determine if they are sick, (if there is a disease, you can see) Once the owner is, the dog is a dog is a sick dog is a dog, which is a dog (you must shoot in one day), and everyone only has the right to shoot her own dog, there is no right to kill other people. Dog.

On the first day, everyone was finished, but the gun didn't ring. After the third day, a gunshot came, and asked a few sick dogs in the village, how to calculate it? Please write a process of this test questions according to the question of the question!

Int idog; // Disease number int NDog; // Dog's number int pdog; // number; equal to the number of dogs BOOL HAVELOOK = FALSE;

For (int i = 1; i

{

IDOG = i; // Number of sick dogs

For (int J = 1; j <= pdog; j ) // per person {int Lookidog = LookDog (); // Observer dog, return to see the number of sick dogs (LOOKIDOG)

{

Killdog (PDOG [J]);

HavelOok = true;

}

}

IF (Havelook) Return Idog;

}

转载请注明原文地址:https://www.9cbs.com/read-118577.html

New Post(0)