上次吃错了,再吃
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int i;
struct node *p;
}lin;
void main()
{
int i,j,n;
lin *head,*p,*q,*k,*l;
while(scanf("%d",&n)!=EOF)
{
head=(lin *)malloc(sizeof(lin));
p=head;
scanf("%d",&p->i);
for(i=1;i<n;i++)
{
q=(lin *)malloc(sizeof(lin));
p->p=q;
p=q;
scanf("%d",&p->i);
}
p->p=NULL;
p=head;
j=0;
while(--n)
{
i=head->i+head->p->i;
k=head;
l=head->p;
p=head;
while(p->p!=NULL)
{
if(p->i+p->p->i<i)
{
k=p;
l=p->p;
}
p=p->p;
}
k->i+=l->i;
j+=k->i;
k->p=l->p;
free(l);
}
printf("%d\n",j);
}
}
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int i;
struct node *p;
}lin;
void main()
{
int i,j,n;
lin *head,*p,*q,*k,*l;
while(scanf("%d",&n)!=EOF)
{
head=(lin *)malloc(sizeof(lin));
p=head;
scanf("%d",&p->i);
for(i=1;i<n;i++)
{
q=(lin *)malloc(sizeof(lin));
p->p=q;
p=q;
scanf("%d",&p->i);
}
p->p=NULL;
p=head;
j=0;
while(--n)
{
i=head->i+head->p->i;
k=head;
l=head->p;
p=head;
while(p->p!=NULL)
{
if(p->i+p->p->i<i)
{
k=p;
l=p->p;
}
p=p->p;
}
k->i+=l->i;
j+=k->i;
k->p=l->p;
free(l);
}
printf("%d\n",j);
}
}
[此贴子已经被作者于2007-4-21 21:55:02编辑过]