#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); } } <
|