-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat_reader.cpp
66 lines (55 loc) · 1.75 KB
/
stat_reader.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
#include "stat_reader.h"
#include <iomanip>
#include <iostream>
#include <set>
using namespace std;
namespace transport_catalogue {
namespace output {
void OutputRouteAbout(TransportCatalogue& tc, std::string_view route) {
if (tc.GetRoute(route) == nullptr) {
cout << "Bus "s << route << ": not found"s << endl;
}
else {
BusStat stat = tc.GetStatistics(tc.GetRoute(route));
cout << "Bus "s << route << ": "s << stat.number_of_stops
<< " stops on route, "s << stat.unique_stops
<< " unique stops, "s << std::setprecision(6)
<< stat.real_distance << " route length, "s
<< std::setprecision(6) << stat.curvature
<< " curvature"s << endl;
}
}
void OutputStopAbout(TransportCatalogue& tc, string_view name) {
bool flag = tc.GetStop(name) != nullptr;
set<string_view> buses = tc.GetBuses(name);
if (flag) {
if (buses.size() == 0) {
cout << "Stop "s << name << ": no buses"s << endl;
}
else {
cout << "Stop "s << name << ": buses "s;
for (auto it = buses.begin(); it != buses.end(); ++it) {
if (next(it) != buses.end()) {
cout << (*it) << " "s;
}
else {
cout << (*it);
}
}
cout << endl;
}
}
else {
cout << "Stop "s << name << ": not found"s << endl;
}
}
void OutputAbout(TransportCatalogue& tc, query::Command com) {
if (com.type == query::QueryType::StopX) {
OutputStopAbout(tc, com.name);
}
if (com.type == query::QueryType::BusX) {
OutputRouteAbout(tc, com.name);
}
}
}//namespace output
}//namespace transport_catalogue