📄 yuesefu.cpp
字号:
// yuesefu.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
struct lnode{
int num;
int cliper;
struct lnode *next;
};
typedef struct lnode node;
typedef node* llnode;
llnode createlist(int n)
{
llnode head,r,s;
int clip;
head=(llnode)malloc(sizeof(node));
printf("输入第1个人的密码\n");
scanf("%d",&clip);
head->num=1;
head->cliper=clip;
head->next=NULL;
r=head;
for (int i=2;i<=n;i++)
{
printf("输入第%d个人的密码\n",i);
scanf("%d",&clip);
s=(llnode)malloc(sizeof(node));
s->num=i;
s->cliper=clip;
s->next=NULL;
r->next=s;
r=s;
}
r->next=head;
return head;
}
llnode ysf(llnode h,int m)
{
llnode head,p,q;
int k=1;
head=h;
q=head;
p=q->next;
while (q!=p)
{
k++;
if (k==m)
{
printf("出列的是%d:\n",p->num);
m=p->cliper;
q->next=p->next;
p=q->next;
k=0;
}
else
{
q=p;
p=p->next;
}
}
return q;
}
int main(int argc, char* argv[])
{
llnode h,temp;
int m,n;
printf("输入m值:");
scanf("%d",&m);
printf("输入n值:");
scanf("%d",&n);
h=createlist(n);
temp=ysf(h,m);
printf("最后出列的是%d:\n",temp->num);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -