Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的c 代码

Posted by gardner at 2005-10-09 02:30:25 on Problem 2593
#include <stdio.h>
void main()
{
	int input[100001]={0};
	int left[100001],right[100001];
	long num,sum,i,flag,max;
	scanf("%d",&num);
	while(num!=0){
		for(i=0;i<num;i++)scanf("%d",&input[i]);
		sum=0;
		flag=input[0];
		for(i=0;i<num;i++){
			if(sum>=0)sum+=input[i];
			else sum=input[i];
			if(flag<sum)flag=sum;
			left[i]=flag;
		}
		sum=0;
		flag=input[num-1];
		for(i=num-1;i>=0;i--){
			if(sum>=0)sum+=input[i];
			else sum=input[i];
			if(flag<sum)flag=sum;
			right[i]=flag;
		}
		max=left[0]+right[1];
		for(i=0;i<num-1;i++){
			if(left[i]+right[i+1]>max)max=left[i]+right[i+1];
		}
		printf("%d\n",max);
		scanf("%d",&num);
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator