📄 lx1.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,result[500],n=0,i;
while(1)
{
scanf("%d",&num);
if(num==0)
break;
h=crt(num);
a=sep(h);
result[n]=a;
result[n+1]=h->candy;
n=n+2;
}
for(i=0;i<n;i=i+2)
printf("%d %d\n",result[i],result[i+1]);
ers(h,num);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -