Page 5 of 7
Re: 11059 - Maximum Product
Posted: Thu Aug 06, 2009 11:00 pm
by robz84
hi mf!
if you uncomment my previous code, there will be blank line.
i forgot to uncomment, sorry, but thanks for reply.
exactly i ve tried 3 possibilities, lets the last output is: Case #5: The maximum product is 54.
1.
Case #5: The maximum product is 54. <-- end of output
2.
Case #5: The maximum product is 54.
<-- end of output
3.
Case #5: The maximum product is 54.
<ENTER>
<-- end of output
but all of them is WA, so maybe something is wrong with the calculation, but i dont find the error, the program generates good answer all the sample from this topic and all the sample what i created
(sorry for my english.)
here is the original code (WA) :
Re: 11059 - Maximum Product
Posted: Fri Aug 07, 2009 12:24 pm
by mf
I don't see what's wrong, your code looks fine to me.
Maybe you should try to use java.util.Scanner and its nextInt() method to parse the input (it's more tolerable to whitespace in input, similar to C's scanf)
Re: 11059 - Maximum Product
Posted: Fri Aug 07, 2009 4:34 pm
by robz84
aah, i got AC with the same code, but using Scanner.
thanks for the hint mf, it was very annoying for me.
Re: 11059 - Maximum Product
Posted: Sun Mar 07, 2010 1:59 am
by jhosimar3001
I've got AC. I corrected my mistake...
Re: 11059 - Maximum Product
Posted: Tue May 08, 2012 2:03 pm
by mathgirl
I ve got WA on this nearly 10 times ! I tried previous test inputs and they work fine. Can someone tell me what's wrong with this code ?
Code: Select all
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n,count = 1;
string empty;
while(cin>>n)
{
long long ans = 1;
long long cur;
long long res = 0;
for(int i=0;i<n;i++)
{
cin >> cur;
if(cur > 0)
{
ans = ans*cur;
res = max(res,ans);
}
else
ans = 1;
}
cout << "Case #" << count << ": The maximum product is " << res << ".\n\n";
count++;
getline(cin,empty);
}
return 0;
}
Re: 11059 - Maximum Product
Posted: Wed May 09, 2012 3:50 am
by brianfry713
Doesn't match the sample I/O.
Re: 11059 - Maximum Product
Posted: Thu May 10, 2012 10:25 am
by mathgirl
Thanks you ! I realised my mistake, I was resetting the sum to zero after a negative number. Got AC.
Re: 11059 - Maximum Product
Posted: Fri Jun 29, 2012 8:05 pm
by 3sam
tgis is my code and i got every subm compile error not wrong answer ::
plz help
#include<iostream>
using namespace std;
int main()
{
long long int x,y;
int arr[100];
int z=1;
int j=1;
while(cin>>x)
{
int max=-10000000;
if(x==1)
{
cin>>y;
if(y>0)
{
cout<<"Case #"<<j<<": The maximum product is "<<y<<"."<<endl;
cout<<endl;
}
else
{
cout<<"Case #"<<j<<": The maximum product is "<<"0"<<"."<<endl;
cout<<endl;
}
}
else
{
for(int i=0;i<x;i++)
{
cin>>arr;
}
long long int result=1;
for(int i=0;i<=x;i++)
{
result*=abs(arr);
if(result>=max && result>=0)
{
max=result;
}
}
}
cout<<"Case #"<<j<<": The maximum product is "<<max<<"."<<endl;
cout<<endl;
j++;
}
return 0;
}
Re: 11059 - Maximum Product
Posted: Sat Jun 30, 2012 12:19 am
by brianfry713
prog.cpp: In function ‘int main()’:
prog.cpp:36: error: ‘abs’ was not declared in this scope
prog.cpp:7: warning: unused variable ‘z’
#include <stdlib.h>
You can see the reason for your compile errors if you click My Submissions on the left or go to:
http://uva.onlinejudge.org/index.php?op ... e&Itemid=9
Re: 11059 - Maximum Product
Posted: Sat Jun 30, 2012 3:59 am
by 3sam
Re: 11059 - Maximum Product
Posted: Mon Jul 02, 2012 10:13 pm
by brianfry713
No, your code doesn't match the sample I/O. I was answering your question about why you got a Compile Error.
Re: 11059 - Maximum Product
Posted: Thu Jul 12, 2012 8:50 pm
by gc_tushar
Why I getting WA
Code: Select all
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<sstream>
#include <deque>
#define pb(a) push_back(a)
#define mx 1010
#define inf (1<<30)
#define pie 3.14159265358979323846
#define mems(arr,temp) memset(arr,temp,sizeof arr)
using namespace std;
//int dx[]= {0,0,-1,1};
//int dy[]= {1,-1,0,0};
//int dx[]= {-1,1,-2,2,-2,2,-1,1};
//int dy[]= {-2,-2,-1,-1,1,1,2,2};
main()
{
int n,t=0;
while(cin>>n)
{
long long int arr[100];
for(long long int i=0; i<n; i++)
{
cin>>arr[i];
}
long long int ans=0;
long long int temp=1;
for(int i=0; i<n; i++)
{
temp*=arr[i];
if(temp>ans) ans=temp;
}
temp=1;
for(int i=n-1; i>=0; i--)
{
temp*=arr[i];
if(temp>ans) ans=temp;
}
if(t>0) cout<<endl;
printf("Case #%d: The maximum product is %lld.\n",++t,ans);
}
}
Re: 11059 - Maximum Product
Posted: Tue Jul 17, 2012 3:27 am
by brianfry713
After each test case you must print a blank line.
Re: 11059 - Maximum Product
Posted: Mon Jul 23, 2012 8:35 pm
by ibrahim_habib
this is my code , each time I submit this problem i got WA

, please anyone helps me
Code: Select all
#include<iostream>
using namespace std;
int main()
{
int n, product[18] = {0}, counter = 1;
long long res;
while(cin >> n)
{
res = 1;
for(int i = 0; i < n; i ++)
cin >> product[i];
for(int i = 0; i < n - 1; i ++)
for(int j = i + 1; j < n; j ++)
if(product[i] < product[j])
swap(product[i], product[j]);
if ((n == 1 && product[0] <= 0) || (n == 2 && product[0] == 0))
res = 0;
else
for(int i = 0; i < n; i ++)
if(product[i] > 0)
res *= product[i];
else if(product[i] == 0)
continue;
else if(product[i] < 0)
if((n - i) % 2 == 0)
for( ; i < n; i ++)
res *= product[i];
else
for(i = i + 1; i < n; i ++)
res *= product[i];
cout <<"Case #" <<counter << ": The maximum product is " << res << "." << endl << endl;
counter ++;
}
return 0;
}
Re: 11059 - Maximum Product
Posted: Tue Jul 24, 2012 1:31 am
by brianfry713
Input:
AC output:
Code: Select all
Case #1: The maximum product is 2.