没什么好说的了,标准链表题。
#include<iostream>
using namespace std;

class LinkedList


{
public:
LinkedList* Next;
int Number;
int Password;
void DeleteNext();
LinkedList* Append(int Number,int Password);
LinkedList(int Number,int Password);
};

LinkedList::LinkedList(int Number,int Password)


{
this->Number=Number;
this->Password=Password;
this->Next=this;
}

void LinkedList::DeleteNext()


{
LinkedList* temp=Next;
Next=temp->Next;
delete(temp);
}

LinkedList* LinkedList::Append(int Number,int Password)


{
LinkedList* temp
=new LinkedList(Number,Password);
temp->Next=this->Next;
this->Next=temp;
return temp;
}

int main()


{
LinkedList* head;
int Count,people,Count1,password;
//Construct Linked List
while(cin>>people>>Count)

{
cin>>password;
head=new LinkedList(1,password);
for(Count1=2;Count1<=people;Count1++)

{
cin>>password;
head=head->Append(Count1,password);
}
//Exit Queues
while(head->Next != head)

{
for(Count1=Count;Count1>1;Count1--)
head=head->Next;
cout<<head->Next->Number<<' ';
Count=head->Next->Password;
head->DeleteNext();
}
cout<<head->Number<<endl;
delete(head);
}
return 0;
}
转载于:https://www.cnblogs.com/FancyMouse/articles/219739.html