-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVa 10281.cpp
75 lines (67 loc) · 2.18 KB
/
UVa 10281.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*BISMILLAHIR RAHMANIR RAHIM*/
#include<bits/stdc++.h>
#define lli long long int
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ALL(x) x.begin(), x.end()
#define print(x) cout<<x<<endl
#define pb(x) push_back(x)
#define cases(x, y) for(int x=1; x<=y; x++)
#define PI acos(-1.0)
#define maxiii(a, b, c) max(max(a, b), c)
#define miniii(a, b, c) min(min(a, b), c)
#define nl cout<<endl
#define printcase(c, n) cout << "Case " << c << ": " << n <<endl
#define printcaseii(c, n, m) cout << "Case " << c << ": " << n << " " << m <<endl
#define vprint(vec) for(int i=0; i<vec.size(); i++){cout << vec[i] << " ";}cout<<endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
lli input(){lli x; cin >> x; return x;}
void display(int ar[], int first, int last){for(int i=first; i<last; i++){cout << ar[i] << " ";}cout<<endl;}
void display(vector<int> ar, int first, int last){for(int i=first; i<last; i++){cout << ar[i] << " ";}cout<<endl;}
lli hour, minute, second, speed;
void split(string s){
int tmp=0, r=1;
for(int i=0; i<s.size(); i++){
if(s[i]>='0' and s[i]<='9'){
tmp*=10;
tmp += (s[i]-'0');
if(i==1){hour = tmp; r=1; tmp=0;}
if(i==4){minute = tmp; r=1; tmp=0;}
if(i==7){second = tmp; r=1; tmp=0;}
if(i==s.size()-1 && i>7){speed = tmp; r=1; tmp=0;}
}
}
}
lli prevTimeInSecond, nowTimeInSecond, prevSpeed;
double dist = 0.0;
void solve(string s){
split(s);
nowTimeInSecond = (hour*3600) + (minute*60) + second;
if(prevSpeed != speed){
dist += ((nowTimeInSecond - prevTimeInSecond)*prevSpeed)/3600.00;
}
else{
dist += ((nowTimeInSecond - prevTimeInSecond)*speed)/3600.00;
}
if(s.size()==8){
cout << s << " " << fixed << setprecision(2) << dist << " km" << endl;
}
prevTimeInSecond = nowTimeInSecond;
prevSpeed = speed;
}
int main(){
FastIO;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
/*int tc = 1;
cin >> tc;
for(int i=1; i<=tc; i++){
solve(i);
}*/
string s;
while(getline(cin, s)){
solve(s);
}
return 0;
}