#include #include #include using namespace std; #include "GasStation.cpp" int main(int argc, char **argv) { int i; class Solution TheClass; int retval; vector G, C; string s; istringstream ss; if (argc != 2) { fprintf(stderr, "usage: a.out num (or - and then put the two arrays on the first two lines of standard input.\n"); exit(1); } if (strcmp(argv[1], "-") == 0) { if (!getline(cin, s)) { fprintf(stderr, "You need to enter the gas amounts on line one.\n"); exit(1); } ss.clear(); ss.str(s); while (ss >> i) G.push_back(i); if (!getline(cin, s)) { fprintf(stderr, "You need to enter the cost amounts on line two.\n"); exit(1); } ss.clear(); ss.str(s); while (ss >> i) C.push_back(i); if (C.size() != G.size()) { fprintf(stderr, "The number of gas and cost elements must be the same.\n"); exit(1); } } else { if (atoi(argv[1]) == 1) { G.push_back(1); G.push_back(2); G.push_back(3); G.push_back(4); G.push_back(5); C.push_back(3); C.push_back(4); C.push_back(5); C.push_back(1); C.push_back(2); } if (atoi(argv[1]) == 2) { G.push_back(2); G.push_back(3); G.push_back(4); C.push_back(3); C.push_back(4); C.push_back(3); } } retval = TheClass.canCompleteCircuit(G, C); cout << retval << endl; exit(0); }