Page 2 of 3
m2 WA
Posted: Mon Feb 18, 2008 11:23 pm
by nahid
i'm getting WA on this code. could u tell pls, why?
Code: Select all
#include<stdio.h>
int main()
{
double spd,pspd,pdis=0,tdis=0,itime=0,ctime;
long int hour;
int min,sec;
char c1,c2,c3;
while(scanf("%ld%c%d%c%d%c",&hour,&c1,&min,&c2,&sec,&c3)!=EOF)
{
if(c3==' ')
{
scanf("%lf",&spd);
ctime = (double)hour + (double)min/60 + (double)sec/3600;
if(tdis!=0)
{
pdis = (double)pspd * (double)(ctime - itime);
}
itime = ctime;
pspd = spd;
}
else
{
ctime = (double)hour + (double)min/60 + (double)sec/3600;
tdis = (double)spd * (double)(ctime - itime);
if(hour<10)
printf("0");
printf("%ld%c",hour,c1);
if(min<10)
printf("0");
printf("%d%c",min,c2);
if(sec<10)
printf("0");
printf("%d %.2lf km\n",sec,(tdis+pdis));
}
}
return 0;
}
10281 - Problem A: Average Speed
Posted: Fri Feb 22, 2008 1:08 pm
by ishtiaq ahmed
This code hangs for WA. Anybody help me?
Code: Select all
/*
Problem No: 10281
Problem : Average Speed
Algorithm: Adhoc
Author : Ishtiaq Ahmed
*/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
char str[1000];
double temp, tempo, pre_hour, total_distance = 0, pre_min, pre_sec, hour, min, sec, distance, total_time, avg_speed;
int main()
{
//freopen("c:\\input.txt", "r", stdin);
//freopen("c:\\output.txt", "w", stdout);
double count;
gets(str);
sscanf(str, "%lf:%lf:%lf %lf", &pre_hour, &pre_min, &pre_sec, &distance);
//scanf("%*c");
total_time = 0;
avg_speed = distance / 60 / 60;
int print_flag;
int flag;
while(gets(str))
{
total_time = 0;
print_flag = 1;
count = -1;
sscanf(str, "%lf:%lf:%lf %lf", &hour, &min, &sec, &count);
if(fabs(count +1) > 0.000001)
// if(count != -1)
{
print_flag = 0;
distance =count;
}
flag = 0;
if(pre_sec > sec)
{
total_time += (sec + 60 - pre_sec);
flag = 1;
}
else
total_time += (sec - pre_sec);
temp = pre_min;
if(flag == 1)
temp++;
flag = 0;
if(temp > min)
{
flag = 1;
total_time += (min + 60 - temp) * 60;
}
else
total_time += (min - temp) * 60;
temp = pre_hour;
if(flag == 1)
temp++;
flag = 0;
total_time += (hour - temp) * 60 * 60;
tempo = total_time * avg_speed;
total_distance += tempo;
if(print_flag == 1)
{
if(hour < 10)
printf("0");
printf("%.0lf:", hour);
if(min < 10)
printf("0");
printf("%.0lf:",min);
if(sec < 10)
printf("0");
printf("%.0lf ",sec);
printf("%.2lf km\n", total_distance + .0000001);
}
pre_hour = hour;
pre_min = min;
pre_sec = sec;
avg_speed = distance / 60 / 60;
}
return 0;
}
10281 - Average Speed
Posted: Thu Apr 02, 2009 11:01 pm
by sazzadcsedu
can someone post me some some good i/o???
10281 - Average Speed
Posted: Tue Apr 05, 2011 11:41 am
by m_helal
What is the problem in that code ? plz help me
#include<stdio.h>
#include<string.h>
int main()
{
long sec,speed,i,j,temp;
long double distance;
sec=0,speed=0;
distance=0;
char str[100];
while(gets(str))
{
int len = strlen(str);
if(len>8)
{
temp = ((((str[0]-'0')*10)+(str[1]-'0'))*60*60)+
((((str[3]-'0')*10)+(str[4]-'0'))*60)+
(((str[6]-'0')*10)+(str[7]-'0'));
distance+=((temp-sec)*speed)/3600;
sec = temp;
speed = 0;
for(i=len-1,j=1;i>8;i--,j*=10)
{
speed+=(str-'0')*j;
}
}
else
{
temp = ((((str[0]-'0')*10)+(str[1]-'0'))*60*60)+
((((str[3]-'0')*10)+(str[4]-'0'))*60)+
(((str[6]-'0')*10)+(str[7]-'0'));
distance+=((temp-sec)*speed)/3600.0;
sec = temp;
for(i=0;i<8;i++)
{
printf("%c",str);
}
printf(" %.2Lf km\n",distance);
}
}
return 0;
}
Re: 10281 - Average Speed
Posted: Wed Jun 15, 2011 2:00 pm
by live_lie
what will be the output for this input
00:00:01 100
01:00:01 50
00:00:01
please someone answer
10281 - Average Speed WA
Posted: Sat Nov 19, 2011 5:13 pm
by sijan
I am getting WA...Plzz help me...
Re: 10281 - Average Speed WA
Posted: Thu Jan 19, 2012 2:03 am
by brianfry713
Try rewriting it so it will pass with extra spaces and missing leading zeros in the input.
Re: 10281 - Average Speed
Posted: Fri Aug 03, 2012 11:57 am
by tzupengwang
Could anyone help with my WA?
I can't figure out the tricky part in the question~
Re: 10281 - Average Speed
Posted: Fri Aug 03, 2012 11:45 pm
by brianfry713
now should be a double.
Re: 10281 - Average Speed
Posted: Tue Aug 07, 2012 7:38 pm
by tzupengwang
Thanks for your help~
I've changed "now" to double as the above but still receive WA now
Are there further problems with it?
Re: 10281 - Average Speed
Posted: Tue Aug 07, 2012 11:40 pm
by brianfry713
Re: 10281 - Average Speed
Posted: Fri Aug 10, 2012 6:19 pm
by tzupengwang
OH~
I see, so this one requires BIG NUM CALCULATION~
Re: 10281 - Average Speed
Posted: Fri Aug 10, 2012 10:07 pm
by brianfry713
No, my AC C++ code uses only int and double for calculations. Your code does overflow where mine doesn't.
Re: 10281 - Average Speed
Posted: Sat Aug 11, 2012 6:45 pm
by tzupengwang
Thanks for your help
I alter my codes again, which do not overflow and gets right with your I/O
However, I am still receiving WA!
What other problem is happening?
Re: 10281 - Average Speed
Posted: Mon Aug 13, 2012 11:50 pm
by brianfry713
It could be a precision error now. Try updating your now variable at each query.