【算法】猴子选大王问题

来源:互联网 发布:java中的clone方法 编辑:程序博客网 时间:2024/05/16 11:53


#define MAX 100#include <stdio.h>void main(){int a[MAX];int i,j=0,k=0,n,m;  //n:monkey  m:numberprintf("****The king of monkey****\n");printf("The number of the monkey:");scanf("%d",&n);printf("The number to read:");scanf("%d",&m);printf("The king is NO.");for(i=0;i<n;i++)a[i]=i+1;i=-1;while(k<n-1){while(j<m){i++;if(i==n) i=0;if(a[i]!=0) j++;}j=0;a[i]=0;k++;}i=0;while(a[i]==0) i++;printf("%d\n",a[i]);}


原创粉丝点击