⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 猴子选大王.txt

📁 是一个数学的应用问题:   已知n个人(以编号1
💻 TXT
字号:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define n 20
#define m 5
typedef struct monkey
{
  int num;
  struct monkey *next;
} Monkey,*LINK;
int main()
{
   LINK p,head,p2;
   int i;
   head=p=p2=(LINK)malloc(sizeof(Monkey));
   for(i=1;i<n;i++)
   {
     p=(LINK)malloc(sizeof(Monkey));
  p2->next=p;
  p2=p;
   }
   p2->next=head;
   p=head;
   printf("对猴子进行编号!\n");
      for(i=1;i<=n;i++)
   {
     p->num=i;
  printf("%d号猴子:%d\n",p->num,p->num);
  p=p->next;
   }
   i=0;
   p=head;
   while(1)
   {
   i++;
   printf("%d号猴子报:%d\n",p->num,i);if(p->next==p) break;
   
   if(i==m)
   {
   i=0;
   printf("%d号猴被淘汰\n",p->num);
   printf("\n");
   p2->next=p->next;
   p=p2->next;
   continue;
   }
   else
   {
 if(i==m-1) p2=p;
   p=p->next;
   }
   }
   
   printf("胜出:%d",p->num);
   getch();

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -