#include<stdio.h>
#include<malloc.h>
typedef struct node
{
int data;
struct node *next;
} Node;
void ysflb(int N,int M)?
{
Node *head=NULL, *p=NULL,*r=NULL;//初始化?
head = (Node*)malloc(sizeof(Node)); //分配空间?
if(! head)
{
printf("内存分配失败");
return ;
}
head->data =1;
head->next = NULL;
p = head;
for(int i=2; i<=N; i++)
{
r=(Node*)malloc(sizeof(Node));
r->data=i;
r->next=NULL;
p->next=r;
p=r;
}//输入所有链表数据
p->next=head;
p=head;
//进行循环连接
while(p->next != p)
{
for(int i=1; i<M; i++)
{
r=p;
p=p->next;
}
printf("%d ",p->data);
r->next=p->next;//删除p?
p=p->next;
}
printf("%d",p->data);
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
ysflb(n,m);
return 0;
}
#include<stdio.h>
#include<malloc.h>
typedef struct node
{
int data;
int Password;
struct node *next;
} Node;
void ysflb(int N,int M)
{
Node *head=NULL, *p=NULL,*r=NULL;//初始化
head = (Node*)malloc(sizeof(Node)); //分配空间
if(! head)
{
printf("内存分配失败");
return ;
}
head->data =1;
head->next = NULL;
scanf("%d",&head->Password);
p = head;
for(int i=2; i<=N; i++)
{
r=(Node*)malloc(sizeof(Node));
r->data=i;
r->next=NULL;
scanf("%d",&r->Password);
p->next=r;
p=r;
}//输入所有链表数据
p->next=head;
p=head;
//进行循环连接
while(p->next != p)
{
for(int i=1; i<M; i++)
{
r=p;
p=p->next;
}
printf("Num=%d Password=%d\n",p->data,p->Password);
M=p->Password;
r->next=p->next;//删除
p=p->next;
}
printf("Num=%d Password=%d",p->data,p->Password);
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
ysflb(n,m);
return 0;
}