📄 用c++编写的约瑟夫环.txt
字号:
#include<stdlib.h>
#include<iostream.h>
typedef struct LNode
{int num,pwd;
struct LNode *next;
}LNode, *LinkList;
void main()
{
int a,i=1,m,n,j;//m为报数上限值,n为人数,j为输入的密码;
cout<<"please enter m:";
cin>>m;
cout<<"please enter n:";
cin>>n;
LinkList head,p,pt;
while(i<=n)
{
pt=new LNode;
if(i==1)
{
p=head=pt;
cout<<"please enter the password:";
cin>>j;
p->num=i;
p->pwd=j;
i++;
}else
{
p->next=pt;
p=pt;
cout<<"please enter the password:";
cin>>j;
p->num=i;
p->pwd=j;
i++;
}
}p->next=head;
for(i=1;i<=n;i++)
{
for(a=1;a<m;a++)
p=p->next;
pt=p->next;
m=pt->pwd;
cout<<pt->num<<'\n';
p->next=pt->next;
free(pt);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -