-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
49 lines (46 loc) · 1.43 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
#include "BookExchange.hpp"
#include <iostream>
#include <fstream>
#include <string>
BookExchange parseBookExchange (std::ifstream& input, Graph*& G) {
std::string line;
std::getline(input, line);
G = new Graph (std::stoi(line));
std::getline(input, line);
while (getline(input, line) && line.size() != 0) {
int delimPos = line.find(',');
int v1 = std::stoi(line.substr(0, delimPos));
int v2 = std::stoi(line.substr(line.find(',') + 1,
line.size() - delimPos - 1));
G->addEdge(v1, v2);
}
return BookExchange (G);
}
std::vector<int> parseWishList (std::ifstream& input) {
std::string line;
std::vector<int> wishList;
while (getline(input, line) && line.size() != 0) {
wishList.push_back(std::stoi(line));
}
return wishList;
}
int main(int argc, char *argv[]) {
if (argc != 2) {
std::cout << "Invalid arguments" << std::endl;
return 1;
}
std::ifstream input (std::string(argv[1]), std::ifstream::in);
Graph* G;
BookExchange BookEx = parseBookExchange(input, G);
std::string line;
std::vector<int> wishList = parseWishList(input);
if (BookEx.isPossible(wishList)) {
std::cout << "Yes, wish list can be fulfilled with the book exchange" << std::endl;
}
else {
std::cout << "No, wish list cannot be fulfilled with the book exchange" << std::endl;
}
delete G;
G = nullptr;
return 0;
}