keymasterviriya1150

Untitled

Sep 8th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int N;
  6.  
  7.     while(1)
  8.     {
  9.         cin >> N;
  10.         if(N==0)
  11.             break;
  12.         int ar[N];
  13.         for(int i=0;i<N;i++)
  14.             cin >> ar[i];
  15.            
  16.         int maxend=0,maxfar=0;
  17.         for(int i=0;i<N;i++)
  18.         {
  19.             maxend+=ar[i];
  20.             if(maxend<0)
  21.                 maxend=0;
  22.             if(maxfar<maxend)
  23.                 maxfar=maxend;
  24.         }
  25.         if(maxfar<=0)
  26.             cout <<"Losing streak."<<endl;
  27.         else cout <<"The maximum winning streak is "<<maxfar<<"."<<endl;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment