Code For Alls..!

get the code!!

Sunday, 23 July 2017

Max Winning Streak Game Points

Alok is playing N round of card games with his friend Brinda. He gets postive or negative points based on whether he won or lost in a specific round. Alok can also get zero points in case of a tie.
Given the points obtained in N rounds, the program must print the maximum sum of points obtained in any of the winning streak sequence.
Input Format:
The first line contains N.
The second line contains the points P(i), i=1 to N with the points separated by a space.
Output Format:
The first line contains M which represents the maximum number of points obtained in any of the winning sequence.
Boundary Conditions:
3 <= N <= 100
-100 <= P(i) <= 100
Example Input/Output 1:
Input:
7
9 2 3 -1 1 2 4
Output:
14
Example Input/Output 2:
Input:
15
11 20 6 7 -4 2 -5 15 8 3 16 8 3 -1 -2
Output:
53
 C code:
#include<stdio.h>
#include <stdlib.h>
int main()
{
int n,i,j,a[100];
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int m=0,s=0;
for(i=0;i<n;i++)
{
   if(a[i]>=0) 
   s=s+a[i];
   else
   {
    if(m<s)
    m=s;
    s=0;
   }
}
if(m<s)
m=s;
printf("%d",m);   
}

No comments:

Post a Comment