| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:救命啊 我要疯了 牛人帮我看下,是不是我漏了什么啊?In Reply To:救命啊 我要疯了 牛人帮我看下,是不是我漏了什么啊? Posted by:poin at 2009-05-14 14:30:45 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int a[100010],b[100010];
int n;
while(scanf("%d",&n),n)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
int flag=0;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]<0)
flag++;
}
int sum=0,k=0,kk=0;
for(int i=0;i<n;i++)
{
if(a[i]>=0)
{
sum+=a[i];
kk++;
if(i==n-1)
b[k++]=sum;
}
else
{
b[k++]=sum;
sum=0;
}
}
sort(b,b+k);
if(b[k-1]>0&&b[k-2]==0&&kk>1)
{
printf("%d\n",b[k-1]);
continue;
}
//cout<<k<<endl;
//cout<<b[2]<<endl;
//cout<<b[k-1]<<" "<<b[k-2]<<endl;
if(b[k-1]==0)
{
sort(a,a+n);
printf("%d\n",a[flag-1]+a[flag-2]);
}
else
if(b[k-1]!=0&&b[k-2]==0)
{
sort(a,a+n);
//cout<<a[flag-1]<<endl;
printf("%d\n",b[k-1]+a[flag-1]);
}
else
printf("%d\n",b[k-2]+b[k-1]);
}
return 0;
}
你再帮我看看这有什么漏洞??
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator