
#include
#include
#include
typedef struct node
{
int data;
struct node *next;
}node;
node* create(node*&L,int k)
{
L=(node*)malloc(sizeof(node));//头节点
node *p;
L->next=NULL;
node*r;
r=L;
int i;
for(i=0;i
p=(node*)malloc(sizeof(node));
scanf("%d",&(p->data));
p->next=NULL;
r->next=p;
r=p;
}
return L;
}
int maxx(node*L)
{
int max=0;
int sum=0;
node*p=L->next;
while(p!=NULL)
{
sum+=p->data;
if(sum<0)
sum=0;
if(sum>max)
max=sum;
p=p->next;
}
return max;
}
int main()
{
node*L;
int k;
scanf("%d",&k);
create(L,k);
printf("%d",maxx(L));
return 0;
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)