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

📄 xin1.cpp

📁 数据库的几个程序
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
typedef struct list
{
	int candy;
	struct list *next;
}link;
#define creatlink(p)  p=(link *)malloc(sizeof(link));
#define del(p)   free((void *)p);
link *crt(int n)
{
	int c,i=1;
	link *h,*p,*last;
	creatlink(h);
	last=h;
	scanf("%d",&h->candy);
	for(i=1;i<n;i++)
	{
		scanf("%d",&c);
		creatlink(p);
		p->candy=c;
		last->next=p;
		last=p;
		
	}
	last->next=h;
	return h;
}
void ers(link *h,int n)
{
	int i;
	link *p=h,*q;
	for(i=0;i<n;i++)
	{
		q=p;
		p=p->next;
		del(q);
	}
}

int sep(link *head)
{
    int count=0,x,y,i;
	link *p;
	while(1)
	{
      
	       x=head->candy/2;
           p=head->next;
	    while(p->candy==head->candy&&p!=head)
		   p=p->next;
	       if(p==head)i=1;
	       if(i==1)break;
	       count++;
	 
        while(p!=head)
		{
          y=p->candy/2;
          p->candy=p->candy/2+x;
          x=y;
          
		  if((p->candy%2)==1)p->candy=p->candy+1;  
	      
	      p=p->next;
		}
          head->candy=head->candy/2+x;
          if((p->candy)%2==1)
		  head->candy=head->candy+1;
  
	}
	   return count;
}
void main()
{
	link *h;
	int num,a,result1,result2;
	while(1)
	{
	   scanf("%d",&num);
	   if(num==0)
	   break;
	   h=crt(num);
	   a=sep(h);
	   result1=a;
	   result2=h->candy;
	   printf("%d %d\n",result1,result2);
       ers(h,num);
	 }
}

⌨️ 快捷键说明

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