ACM problem 10071

Started by
4 comments, last by iamcreasy 14 years, 4 months ago
I am trying to solve a ACM problem # 10071 This is the link of the problem: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=1012 I think i have fulfilled every conditions, but still it is showing wrong answer! I have tried a lot, but still could not figured out the problem. :( Indicating the problem will be enough.I will solve it by myself. Is there anyone who can help me out. Source: ------------------------------------------------------------------------- #include<stdio.h> int main() { int v,t; double a, s; while((scanf("%d %d",&v, &t)) == 2) { if (t==0 || t < 0) { s = 0; printf("%.0lf\n", s); continue; } a = (double)v/t; t *= 2; s = 0.5 * a * t * t; if(s<0) { s *= -1; printf("%.0lf\n", s); } else printf("%.0lf\n", s); } return 0; } ------------------------------------------------------------------
Advertisement
I think you are being too sophisticated about signs. If the velocity is negative, you probably want to see negative displacement as well.

#include <stdio.h>int main() {  int v,t;  while (scanf("%d %d", &v, &t)==2)    printf("%d\n",2*v*t);  return 0;}
and this is the solution with c++:

#include<iostream>
using namespace std;
int main()
{
int v,t;
while(cin>>v>>t)
cout<<2*v*t<<endl;
return 0;
}

and i have accepted when i send my answer
ESOO
Quote:Original post by iamcreasy
I am trying to solve a ACM problem # 10071

This is the link of the problem:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=1012

I think i have fulfilled every conditions, but still it is showing wrong answer!
I have tried a lot, but still could not figured out the problem. :(

Indicating the problem will be enough.I will solve it by myself.

Is there anyone who can help me out.

Source:
-------------------------------------------------------------------------
#include<stdio.h>

int main()
{
int v,t;
double a, s;
while((scanf("%d %d",&v, &t)) == 2)
{
if (t==0 || t < 0)
{
s = 0;
printf("%.0lf\n", s);
continue;
}
a = (double)v/t;
t *= 2;
s = 0.5 * a * t * t;
if(s<0)
{
s *= -1;
printf("%.0lf\n", s);
}
else
printf("%.0lf\n", s);
}

return 0;
}
------------------------------------------------------------------


the problem is you are assuming that there will be exactly two test case, in reality there will be many more case and you should read until EOF.
ESOO
Quote:Original post by Esoo
the problem is you are assuming that there will be exactly two test case, in reality there will be many more case and you should read until EOF.


That's not right. He is reading for as long as he can read two arguments, which is precisely what he should do.
Thanks,i solved it.

[Edited by - iamcreasy on December 3, 2009 1:08:36 PM]

This topic is closed to new replies.

Advertisement