⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 josph.cpp

📁 编号是1
💻 CPP
字号:
#include <iostream>
typedef struct node
{
    int num;
	int code;
	struct node *next;
}node,*list;
list creat()
{
    node *head,*rear,*r;
	int num,m;
	head=(node *)malloc(sizeof(node));
	rear=head;
	printf("input the student's num and code:\n");
	scanf("%d%d",&num,&m);
	head->num=num;
	head->code=m;
	printf("input the student's num and code:\n");
	scanf("%d%d",&num,&m);
	while(m!=0)
	{
	    r=(node *)malloc(sizeof(node));
		r->num =num;
		r->code=m;
		rear->next=r;
		rear=r;
		printf("input the student's num and code:\n");
		scanf("%d%d",&num,&m);
	}
	rear->next=head;
	return(rear);
}
int linklength(list l)
{
    node *p;
	int i=1;
	p=l->next;
	while(p!=l)
	{
	    p=p->next;
		i++;
	}
	return i;
}
void main()
{
    list l;
	node *p,*r;
	int m,n;
	l=creat();
	n=linklength(l);
	printf("there are %d students!\n",n);
	p=l;
	printf("input the start code:\n");
	scanf("%d",&m);

	while(n>0)
	{
	    for(int i=m;i>1;i--)
			p=p->next;
		r=p->next;
		m=r->code;
		printf("num=%d,code=%d:\n",r->num,r->code);
	    
		p->next=r->next;
		free(r);
		n--;
	}

	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -