Posted: Mon Jan 02, 2006 4:47 pm
Declare check[][] and money[] globally or as static in main().
Code: Select all
Thank you mf I was wrong in thinking..
AC.... :wink:
Code: Select all
he can identify patterns of consecutive wins and elaborate a win-win strategy.
A bet is an amount of money and is either winning (and this is recorded as a positive value).
Code: Select all
#include<stdio.h>
#include<vector>
using namespace std;
int main()
{
int n,re;
re = scanf("%d",&n);
while(n)
{
vector<int> input;
int a;
for(int j=1;j<=n;j++)
{
scanf("%ld",&a);
input.push_back(a);
}
int sum = 0,maxs = 0;
int i = 0,j;
while(i<input.size())
{
sum = 0;
j = i;
while(j<input.size())
{
sum = sum + input[j];
j++;
maxs = max(sum,maxs);
}
i++;
}
if(maxs>0)
printf("The maximum winning streak is %d.\n",maxs);
else
printf("Losing streak.\n");
re = scanf("%d",&n);
}
return 0;
}
Code: Select all
#include <stdio.h>
#include <iostream>
#include <iterator>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)&&n!=0){
std::istream_iterator<int> int_it(cin),end;
int sum=*int_it++;
for(int i=2;i<n;++i)
{
sum+=*int_it++;
if(sum<0)
sum=0;
}
sum+=*int_it;
if(sum>0)
printf("The maximum winning streak is %d.\n",sum);
else
printf("Losing streak.\n");
}
}
and the second's:Losing streak.
How could be this possible?The maximum winning streak is 1.
Code: Select all
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include <queue>
#include <stack>
#include<string>
#include<list>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
int n,x;
long long sum,max;
while(scanf("%d",&n) == 1 && n)
{
max = -1;
sum = 0;
while(n--)
{
scanf("%d",&x);
if(x < 0)
{
if(max < sum)
max = sum;
sum =0;
}
else
sum = sum + x;
}
if(max < sum)
max = sum;
if(max > 0)
printf("The maximum winning streak is %lld.\n",max);
else
printf("Losing streak.\n");
}
return 0;
}
output:5
12 -4
-3 4
9
0
The maximum winning streak is 18.
Code: Select all
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int sum,n[10005],tmp[10005],big;
while(1)
{
scanf("%d",&sum);
if(sum==0)
break;
for(int i=0;i<sum;i++)
{
scanf("%d",&n[i]);
tmp[i]=n[i];
}
big=*max_element(n,n+sum);
for(int i=1;i<sum;i++)
{
for(int j=0;j<sum-i;j++)
{
tmp[j]+=n[j+i];
if(big<tmp[j])
big=tmp[j];
}
}
if(big<1)
printf("Losing streak.\n");
else
printf("The maximum winning streak is %d.\n",big);
}
}