-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapper.cpp
56 lines (51 loc) · 1.33 KB
/
mapper.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
#include <algorithm>
#include <iostream>
#include <string>
const int row_numer_price = 10;
const std::string
parser_row(const std::string &line, const int row_number)
{
auto begin = line.begin();
auto current = line.begin();
int current_row{1};
bool in_quotes = false;
while (current != line.end())
{
if (*current == '"')
{
in_quotes = !in_quotes;
}
else if (!in_quotes && *current == ',')
{
if (current_row == row_number)
{
return {begin, current};
}
begin = current + 1;
current_row++;
}
++current;
}
return {};
}
// int
// main()
// {
// std::string line = "6949526,\"Brooklyn's heart, Ft Greene! 1day free bicycle\",36434721,Gabriel,Brooklyn,Fort Greene,40.68503,-73.9742,Entire home/apt,160,1,70,2019-06-30,1.43,1,356";
// int row_number = 10; // Example row number to parse
// std::string result = parser_row(line, row_number);
// // Output the result
// std::cout << "Parsed row: " << result << std::endl;
// return 0;
// }
int
main(int argc, char **argv)
{
std::string line;
while (std::getline(std::cin, line))
{
std::cout << parser_row(line, row_numer_price) << "\t"
<< "1" << std::endl;
}
return 0;
}