📄 Լɪ
字号:
#include <iostream>
using namespace std;
typedef struct LNode
{
int num,pwd;
struct LNode *next;
}LNode,*LinkList;
int main()
{
while (1)
{
int i,j,m,n,k;
cout<<"Please enter n=";
if(!(cin>>n)) {cout<<"ERROR:That's not a number!";return -1;}
cout<<"Please enter k=";
if(!(cin>>k)) {cout<<"ERROR:That's not a number!";return -2;}
if(k>=n||k==0) cout<<"k is not in the length of 1~n."<<endl;
else
{
LinkList head,tail,p,q;
head=new LNode;
p=head;
for(i=1;i<n;i++)
{
q=new LNode;
p->next=q;
p=q;
}
tail=q;
tail->next=head;
p=head;
for(i=1;i<=n;i++)
{
p->num=i;
cout<<"Please enter No."<<i<<"'s password:";
cin>>p->pwd;
p=p->next;
}
if (tail->num !=k) tail=tail->next;
cout<<"result:";
p=tail ;
for(i=1;i<=n;i++)
{
for(j=1;j<m;j++) p=p->next;
q=p->next;
m=q->next->pwd;
cout<<" "<<q->num;
p->next=q->next;
delete q;
} cout<<endl;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -