Home > Back-end >  Cat and mouse
Cat and mouse

Time:10-07

Have a cat will miss a to the mouth of the mouse?
The cat caught a n input (temporary) mice, it wants to look at the mouse's intelligence quotient, the mouse in a circle, and starting from the serial number of the first mouse count (or count), eat the mouse every count to three, and then from the next mouse began to count, the game loop until only the last mouse, the mouse is released, could you tell me if you are this clever rat, want to survive, you should number to which position, please programming solution,
The problem is how to programming

CodePudding user response:

Ha ha

Cat and mouse

Fox hunting rabbits

https://blog.csdn.net/qq_45861670/article/details/104069338

For your reference ~

CodePudding user response:

Typedef struct _stuMouse
{
_stuMouse * pNext;
Int nNode;
} stuMouse;


Int ncount=0;
While (ncount & lt;
=1){
Printf (" please input the number of mice (greater than 1) : ");
The scanf (" % d ", & amp; Ncount);
}

StuMouse pMouseArray=(stuMouse) * * * * malloc (sizeof (stuMouse *) * ncount);
for(int i=0; i{
PMouseArray [I]=(stuMouse *) malloc (sizeof (stuMouse));
}

for(int i=0; i{
PMouseArray [I] - & gt; PNext=pMouseArray [I + 1);
PMouseArray [I] - & gt; NNode=I + 1;
}
PMouseArray [] ncount - 1 - & gt; PNext=pMouseArray [0];
PMouseArray [] ncount - 1 - & gt; NNode=ncount;

StuMouse * pPoint=pMouseArray [0];
StuMouse * pLast=NULL;
Int nEat=1;
While (pPoint - & gt; PNext!=pPoint)
{
NEat++;
PLast=pPoint;
PPoint=pPoint - & gt; PNext;
If (nEat==3)
{
Printf (" Numbers for % d ate my mouse \ n ", pPoint - & gt; NNode);
PLast - & gt; PNext=pPoint - & gt; PNext;
PPoint=pPoint - & gt; PNext;
NEat=1;
}
}
Printf (" * * * * * * ^_^ Numbers for % d rats live * * * * * * ^_^ \ n ", pPoint - & gt; NNode);

for(int i=0; i{
Free (pMouseArray [I]);
}
Free (pMouseArray);

CodePudding user response:

refer to the second floor lirg8405 response:
typedef struct _stuMouse
{
_stuMouse * pNext;
Int nNode;
} stuMouse;


Int ncount=0;
While (ncount & lt;
=1){
Printf (" please input the number of mice (greater than 1) : ");
The scanf (" % d ", & amp; Ncount);
}

StuMouse pMouseArray=(stuMouse) * * * * malloc (sizeof (stuMouse *) * ncount);
for(int i=0; i{
PMouseArray [I]=(stuMouse *) malloc (sizeof (stuMouse));
}

for(int i=0; i{
PMouseArray [I] - & gt; PNext=pMouseArray [I + 1);
PMouseArray [I] - & gt; NNode=I + 1;
}
PMouseArray [] ncount - 1 - & gt; PNext=pMouseArray [0];
PMouseArray [] ncount - 1 - & gt; NNode=ncount;

StuMouse * pPoint=pMouseArray [0];
StuMouse * pLast=NULL;
Int nEat=1;
While (pPoint - & gt; PNext!=pPoint)
{
NEat++;
PLast=pPoint;
PPoint=pPoint - & gt; PNext;
If (nEat==3)
{
Printf (" Numbers for % d ate my mouse \ n ", pPoint - & gt; NNode);
PLast - & gt; PNext=pPoint - & gt; PNext;
PPoint=pPoint - & gt; PNext;
NEat=1;
}
}
Printf (" * * * * * * ^_^ Numbers for % d rats live * * * * * * ^_^ \ n ", pPoint - & gt; NNode);

for(int i=0; i{
Free (pMouseArray [I]);
}
Free (pMouseArray);

Thank you very much
  • Related