每套第三题貌似有点难度,先稍微休息下。
#include <stdio.h>
#include <stdlib.h>
struct Jose
{
int e;
Jose *next;
}Jose;
int main()
{
int n,m;
int i,j;
struct Jose *head;
struct Jose *q; //前一个
struct Jose *p; //当前
while(scanf("%d %d",&n,&m)!=EOF&&n>0&&m>0)
{
head = (struct Jose*)malloc(sizeof(struct Jose));
head->e = 1;
// head->next = head;
q = head;
for(i=2;i<=n;i++)
{
p = (struct Jose*)malloc(sizeof(struct Jose));
p->e = i;
// printf("%d---------",p->e);
q->next = p;
q = p;
}
q->next = head;
p = head;
for(i=n;i>1;i--)
{
for(j=1;j<m;j++) //
{
q = p;
p = p ->next;
}
q->next = p->next;
printf("%d---\n",p->e);
free(p);
p = q->next;
}
printf("%d",p->e);
}
return 0;
}