12709 - Falling Ants
Moderator: Board moderators
-
- New poster
- Posts: 2
- Joined: Mon Dec 09, 2013 10:40 pm
12709 - Falling Ants
#include <iostream>
using namespace std;
int main()
{
int t,l,w,h,result,temp=0,temp2=0;
while(true)
{
cin>>t;
if(t == 0) break;
while(t--)
{
cin>>l>>w>>h;
if(h>temp)
{
result=l*w*h;
temp2=result;
temp=h;
}
if(h==temp)
{
result=l*w*h;
temp=h;
if(temp2<result)
temp2=result;
}
}
cout<<temp2<<endl;
}
return 0;
}
using namespace std;
int main()
{
int t,l,w,h,result,temp=0,temp2=0;
while(true)
{
cin>>t;
if(t == 0) break;
while(t--)
{
cin>>l>>w>>h;
if(h>temp)
{
result=l*w*h;
temp2=result;
temp=h;
}
if(h==temp)
{
result=l*w*h;
temp=h;
if(temp2<result)
temp2=result;
}
}
cout<<temp2<<endl;
}
return 0;
}
Re: 12709 - Falling Ants [Wrong Answer]
Try these cases:
1
1 2 3
1
1 1 1
0
Answer:
6
1
Yours:
6
6
Got it?
By the way, thanks to your code I could realize my own mistake.
1
1 2 3
1
1 1 1
0
Answer:
6
1
Yours:
6
6
Got it?
By the way, thanks to your code I could realize my own mistake.
Re: 12709 - Falling Ants [Wrong Answer]
why wrong ans..here is my code.....
#include<stdio.h>
int main()
{
int i,textCase,l,w,h;
while(scanf("%d",&textCase)&&textCase)
{
int volume1=0,volumeFinal=0,max=0;;
for(i=1; i<=textCase; i++)
{
scanf("%d%d%d",&l,&w,&h);
if(h>=max)
{
volume1=l*w*h;
if(volumeFinal<volume1)
volumeFinal=volume1;
max=h;
}
}
printf("%d\n",volumeFinal);
}
return 0;
}
Any one help me pls.
#include<stdio.h>
int main()
{
int i,textCase,l,w,h;
while(scanf("%d",&textCase)&&textCase)
{
int volume1=0,volumeFinal=0,max=0;;
for(i=1; i<=textCase; i++)
{
scanf("%d%d%d",&l,&w,&h);
if(h>=max)
{
volume1=l*w*h;
if(volumeFinal<volume1)
volumeFinal=volume1;
max=h;
}
}
printf("%d\n",volumeFinal);
}
return 0;
}
Any one help me pls.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 12709 - Falling Ants [Wrong Answer]
Input:AC output: 2
Code: Select all
2
2 2 1
1 1 2
0
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 2
- Joined: Mon Dec 09, 2013 10:40 pm
Re: 12709 - Falling Ants [Wrong Answer]
Thanks aliatti ![:)](./images/smilies/icon_smile.gif)
Now, i solved it.
![:)](./images/smilies/icon_smile.gif)
Now, i solved it.
Re: 12709 - Falling Ants [Wrong Answer]
for(int i=1;;i++)
thank u brianfry713;
thank u brianfry713;
Re: 12709 - Falling Ants [Wrong Answer]
Why runtime error ?!!!Please,any one help me to find a bug in my program...here is my code
Code: Select all
got ac
Last edited by sampad74 on Fri Jul 25, 2014 5:06 am, edited 1 time in total.
Re: 12709 - Falling Ants [Wrong Answer]
Increase arrray limitFirst line of each test case contains an integer T (T <= 100) which denotes the total number of ants
to consider.
Code: Select all
int l[51],w[51],h[51],v,t,i;
Code: Select all
int l[101],w[101],h[101],v,t,i;
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- New poster
- Posts: 2
- Joined: Thu Sep 25, 2014 2:47 pm
Re: 12709 - Falling Ants
i don't know why im gettin a WA
![:oops:](./images/smilies/icon_redface.gif)
Code: Select all
import java.util.Scanner;
class Main {
public static void main(String [] args)
{
Main mc=new Main();
mc.begin();
}
void begin()
{
Scanner sc =new Scanner(System.in);
int cases =sc.nextInt();
int l,w,h,vol=0,mvol=0;
double f=0,max=0;
while(cases!=0)
{ mvol=0;vol=0;
for(int i=0;i<cases;i++)
{
l=sc.nextInt();
w=sc.nextInt();
h=sc.nextInt();
f=h;
if(max<=f)
{
max=f;
vol=l*w*h;
if(mvol<vol)mvol=vol;
}
}
System.out.println(mvol);
cases=sc.nextInt();
}
}
}
![:oops:](./images/smilies/icon_redface.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 12709 - Falling Ants
Try solving it without using floating point.
Check input and AC output for thousands of problems on uDebug!
Re: 12709 - Falling Ants
Change code to
By the way, why did you made f and max double? (int was enough)
Don't forget to remove your code after getting accepted.![8)](./images/smilies/icon_cool.gif)
Code: Select all
while(cases!=0)
{
max = mvol = vol = 0;
..
f=h;
vol=l*w*h;
if(max<f || (max == f && mvol<vol))
{
max=f;
mvol=vol;
}
}
Don't forget to remove your code after getting accepted.
![8)](./images/smilies/icon_cool.gif)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman