-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwostar_day5.cpp
More file actions
41 lines (32 loc) · 1.06 KB
/
twostar_day5.cpp
File metadata and controls
41 lines (32 loc) · 1.06 KB
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
#include <bits/stdc++.h>
using namespace std;
pair<map<int, vector<int>>, vector<vector<int>>> parse_input() {
map<int, vector<int>> dependency;
vector<vector<int>> list_pages;
string line;
while (getline(cin, line)) {
line.erase(remove(line.begin(), line.end(), '\r'), line.end()); // Handle Windows-style line endings
if (line.find('|') != string::npos) {
istringstream iss(line);
int key, value;
char delim;
iss >> key >> delim >> value;
if (delim == '|') {
dependency[key].push_back(value);
}
} else if (line.find(',') != string::npos) {
istringstream iss(line);
vector<int> pages;
int page;
char delim;
while (iss >> page) {
pages.push_back(page);
if (!(iss >> delim) || delim != ',') {
break;
}
}
list_pages.push_back(pages);
}
}
return {dependency, list_pages};
}