//
// main.cpp
// 10281 - Average Speed
//
// Created by Panks on 27/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
double cspeed=0, tdistane=0;
int gh=0, gm=0, gs=0;
string input;
void updatevalues();
void updatevalues(){
int h=0,m=0,s=0, speed=0;
int i=0;
while (input[i]!=':') {
h=h*10+input[i]-'0';
i++;
}
i++;
while (input[i]!=':') {
m=m*10+input[i]-'0';
i++;
}
i++;
while (input[i]!=' ') {
s=s*10+input[i]-'0';
i++;
}
i++;
while (input[i]!='\0') {
speed=speed*10+input[i]-'0';
i++;
}
double time=(h-gh)+((m-gm)/60.0)+((s-gs)/3600.0);
double dis=time*cspeed;
tdistane=dis+tdistane;
cspeed=speed;
gh=h;
gm=m;
gs=s;
}
int main (int argc, const char * argv[])
{
// insert code here...
int h=0, m=0, s=0;
while (getline(cin, input)) {
if (count(input.begin(), input.end(), ' ')) {
updatevalues();
}else{
int i=0;
h=0; m=0; s=0;
while (input[i]!=':') {
h=h*10+input[i]-'0';
i++;
}
i++;
while (input[i]!=':') {
m=m*10+input[i]-'0';
i++;
}
i++;
while (input[i]!='\0') {
s=s*10+input[i]-'0';
i++;
}
double dist=((h-gh)+((m-gm)/60.0)+((s-gs)/3600.0))*cspeed;
double totaldis=tdistane+dist;
printf("%s %.2f km\n", &input[0], totaldis);
}
}
}
Saturday, June 2, 2012
10281 - Average Speed
Labels:
Ad Hoc,
programming
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment