首页 > 代码库 > 123

123

#include<iostream>
#include<malloc.h>
using namespace std;

struct Node
{
int pos;
int code;
struct *Node next;
}
Node *creat(int n)
{
Node *head,*p,*q;
for (int i=1;i<=n;i++)
{
int password;
cin>>password;
p=(struct Node*) malloc(sizeof(Node));
p->code=password;

if (head==NULL) head=p;
else q->next=p;
q=p;
free(p);
}
q->next=p;
return head;
}

int main()
{
int n,m;
cin>>m>>n;
Node *head,*p,*tmp;
head=creat(n);

while (n--)
{
for (int i=1;i<=n+m;i++)
{
tmp=p;
p=p->next;
}
cout<<p->pos;
m=p->code;
p=tmp;
p->next=p->next->next;
p=p->next;
}
return 0;
}

123