Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么re啊

Posted by congcongbebe at 2010-04-01 21:09:41
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator