#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct man)
#define NULL 0
struct man
{
int mum;
struct man *next;
};
struct man *creat(int n)
{
struct man *head,*p1,*p2;
if(n==0)
head=NULL;
if(n!=0)
{
head=p2=p1=(struct man *)malloc(LEN);
head->mum=1;
int i;
i=2;
do
{
p1=(struct man *)malloc(LEN);
p1->mum=i;
p2->next=p1;
p2=p1;
i++;
}while(i<n);
p2=p1;
p1=(struct man *)malloc(LEN);
p2->next=p1;
p2->mum=n-1;
p1->next=head;
p1->mum=n;
}
return(head);
}
void ysf(int n,int s,int d,struct man *head)
{
struct man *p1,*p2,*p3;
p2=p1=head;
int m;
float y;
m=1;
y=1;
int i;
int c=0;
int q=1;
for(i=1;i<=d;)
{
if((m/s)!=0)
{
if((m/s)==(y/s))
{
c++;
printf("第%2d个死亡的人是%2d/n",c,p1->mum);
p3=p1;
p1=p1->next;
free(p3);
p2->next=p1;
i++;
q=1;
m++;
y++;
}
}
p2=p1;
p1=p1->next;
y++;
m++;
q++;
}
}
int main()
{
int n;
int s;
int d;
struct man *head;
printf("请输入总人数 n:");
scanf("%d",&n);
printf("请输入死亡位置s:");
scanf("%d",&s);
printf("请输入死亡人数d:");
scanf("%d",&d);
printf("/n");
if(n<d) {printf("error/n"); return 1;}
if(n<=0){printf("error/n"); return 1;}
if(s<=0){printf("error/n"); return 1;}
if(d<=0){printf("error/n"); return 1;}
head=creat(n);
ysf(n,s,d,head);
return 0;
}