Moderator: Board moderators
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char line[6], tmp[2];
int ho, mo, sec, speed = 0, i;
float distance = 0, time = 0;
while (scanf("%d:%d:%[0-9 ]", &ho, &mo, line)!=EOF)
{
strncpy(tmp, line, 2);
sec = atoi(tmp);
distance+=(ho + mo/60.0 + sec/3600.0 - time)*speed;
time = ho + mo/60.0 + sec/3600.0;
if (strlen(line)>2)
{
for (i = 0; i<4; i++)
line[i] = line[i+3];
speed = atoi(line);
}
else
printf("%02d:%02d:%02d %.02f km\n", ho, mo, sec, distance);
}
return 0;
}%lf%femotional_blindemotional blind#include <stdio.h>
#ifndef ONLINE_JUDGE
#include <io.h>
#include <fcntl.h>
#endif
int main()
{
#ifndef ONLINE_JUDGE
close(0);
open("in.txt",O_RDONLY);
#endif
int h,m,s,col=0;
char str[80],time[10];
long long time1,time2;
double speed,dist=0,t;
while (scanf("%s",time)!=EOF)
{
sscanf(time,"%i%*c%i%*c%i",&h,&m,&s);
str[0]='\0';
gets(str);
time2=(s+60*(((long long)h)*60+m));
if (sscanf(str,"%lf",&t)!=EOF)
{
if (col) dist+=(time2-time1)*speed/3600.0;
col++;
time1=time2;
speed=t;
}
else
{
if (col) printf("%s %.2lf km\n",time,(double)(dist+(time2-time1)*speed/3600.0));
else printf("%s 0.00 km\n",time);
}
}
return 0;
}Sorry, already fixed it.
Now I got Accepted. The only special case of this problem is that there may trailling spaces and speed can be 0 km/hour .
Users browsing this forum: No registered users and 0 guests