Saturday, July 29, 2017

UVa problem solution 10684 - The jackpot

problem link:


Discuss: sum all score if the sum less then zero then set sum zero not when only single score is zero.


try yourself before see the code


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n;
    while(cin >>n&&n)
    {
        int m,sum=0,maxx=-1;
        for(int i = 0; i <n; i++)
        {
            cin >>m;


                sum+=m;

           if(sum<0)
                sum=0;
                if(sum>maxx)
                    maxx=sum;
        }
        if(maxx>0)
            printf("The maximum winning streak is %d.\n",maxx);
        else
            cout <<"Losing streak."<<endl;
    }
    return 0;
}

No comments:

Post a Comment