| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么re啊#include <stdio.h>
#include <stdlib.h>
struct node
{
node *next;
char kid[20];
}*p,*p1,*h,*r;
void ysfh(int n)
{
int i,k,m;
//建立一个循环链表
for(i=1;i<=n;i++)
{
p = (struct node *)malloc(sizeof(node));
scanf("%s",p->kid);
if(h==NULL)
{
h = p;
}
else
{
p1->next = p;
}
p1 = p;
}
p->next = h;
p = h;
scanf("%d,%d",&k,&m);
//把指针移动到编号为k的那个人上面
for(i=0;i<k;i++)
{
p1 = p;
p = p->next;
}
//p1指向了编号为k的那个人
//找到数到m的那人并且删除
while(p1->next!=p1)
{
for(i=0;i<m-1;i++)
{
r = p1;
p1 = p1->next;
}
//p1指向的是删除那个数
printf("%s\n",p1->kid);
r->next = p1->next;
free(p1);
p1=r->next;
}
printf("%s\n",p1->kid);
}
int main()
{
int n;
scanf("%d",&n);
ysfh(n);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator