-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
93 lines (81 loc) · 2.15 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
** GOOGLE PROJECT, 2021
** GoogleHashcode2021
** File description:
** main
*/
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "class.hpp"
Car parseCar(string str)
{
Car *car = new Car();
string tmp2;
stringstream tmp(str);
getline(tmp, tmp2, ' ');
car->_nbStreet = atoi(tmp2.c_str());
for (int i = 0; getline(tmp, tmp2, ' '); i++)
car->_nameStreet.push_back(tmp2);
return *car;
}
Intersec parseIntersec(string str, Intersec *intersec)
{
string tmp2;
stringstream tmp(str);
getline(tmp, tmp2, ' ');
getline(tmp, tmp2, ' ');
getline(tmp, tmp2, ' ');
intersec->_nameStreet.push_back(tmp2);
return *intersec;
}
Street parseStreet(string str)
{
Street *street = new Street();
string tmp2;
stringstream tmp(str);
getline(tmp, tmp2, ' ');
street->_firstInter = atoi(tmp2.c_str());
getline(tmp, tmp2, ' ');
street->_secInter = atoi(tmp2.c_str());
getline(tmp, tmp2, ' ');
street->_name = tmp2;
getline(tmp, tmp2, ' ');
street->_nbSec = atoi(tmp2.c_str());
return *street;
}
void parseCity(string str, City *city)
{
string tmp2;
stringstream tmp(str);
getline(tmp, tmp2, ' ');
city->_nbSec = atoi(tmp2.c_str());
getline(tmp, tmp2, ' ');
city->_nbIntersec = atoi(tmp2.c_str());
getline(tmp, tmp2, ' ');
city->_nbStreet = atoi(tmp2.c_str());
getline(tmp, tmp2, ' ');
city->_nbCars = atoi(tmp2.c_str());
getline(tmp, tmp2, ' ');
city->_nbPoint = atoi(tmp2.c_str());
}
int main(int argc, char**av)
{
City *city = new City();
string str = av[1];
fstream file(str);
getline(file, str, '\n');
parseCity(str, city);
getline(file, str, '\n');
for (int i = city->_nbIntersec; i > 0; i--) {
Intersec *tmp = new Intersec();
tmp->_nbInter = i;
city->_intersec.push_back(parseIntersec(str, tmp));
}
for (int i = city->_nbStreet; i > 0; i--, getline(file, str, '\n')) {
city->_streets.push_back(parseStreet(str));
for (int i = city->_nbCars; i > 0; i--, getline(file, str, '\n'))
city->_cars.push_back(parseCar(str));
return 0;
}