// Problem link >>http://uva.onlinejudge.org/external/106/10684.html
... Adhoc problem .... Tricky ...
#include <bits/stdc++.h>
using namespace std ;
vector<int>v ;
int n ;
int main ()
{
int i , x , a ,mx ;
while (cin>>n && n!=0)
{
mx=0 ;a=0 ;
for (i=1 ; i<=n ; i++)
{
cin>>x ;
a=a+x ;
if (a<0) a=0 ;
mx=max(a,mx) ;
}
if (mx==0) cout<<"Losing streak."<<endl ;
else cout<<"The maximum winning streak is "<<mx<<".\n" ;
}
return 0 ;
}
... Adhoc problem .... Tricky ...
#include <bits/stdc++.h>
using namespace std ;
vector<int>v ;
int n ;
int main ()
{
int i , x , a ,mx ;
while (cin>>n && n!=0)
{
mx=0 ;a=0 ;
for (i=1 ; i<=n ; i++)
{
cin>>x ;
a=a+x ;
if (a<0) a=0 ;
mx=max(a,mx) ;
}
if (mx==0) cout<<"Losing streak."<<endl ;
else cout<<"The maximum winning streak is "<<mx<<".\n" ;
}
return 0 ;
}
No comments:
Post a Comment