新手求教:猴子选大王问题。。错在哪了?
#include<iostream>using namespace std;
void main()
{ int n,i,k,a[100],m,j=0;
cout<<"请输入猴子数为:";
cin>>n;
cout<<"请输入报数;";
cin>>m;
for(i=0;i<n;i++)
a[i]=1;
i=0;
while(j<n)
{k=1;
while(k<m)
{ if(a[i]!=0){k++; i=(i+1)%n;}
else i=(i+1)%n;}
if(a[i]==0)j--;
else a[i]=0;
j++;}
for(i=0;i<n;i++)
{if(a[i]!=0)cout<<i+1<<endl;}
}