2.用数组??
谁做下!
[此贴子已经被作者于2005-12-9 18:00:48编辑过]
long int n,m;
struct Monkey
{
long int number;
struct Monkey *next;
};
struct Monkey *end;
struct Monkey *creat()
{
struct Monkey *q,*p,*head;
long int i=1;
while (i<=m)
{
if(i!=1) q=p;
p=new(struct Monkey);
if (i==1) head=p;
p->number=i;
if (i!=1) q->next=p;
i++;
}
p->next=head;end=p;
return(head);
}
void del(struct Monkey *q,struct Monkey *p)
{
q->next=p->next;
delete(p);
}
long int chooseking()
{
struct Monkey *p,*q;long int i=1;
p=creat();q=end;
while (p->next!=p)
{
lp:if(i==n) {del(q,p);p=q->next;i=1;if (p->next==p) break;goto lp;}
q=p;
p=p->next; i=i+1;
}
return(p->number);
}
void main()
{
cout<<"please m and n:";
cin>>m>>n;
cout<<chooseking();
}