-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (55 loc) · 1.51 KB
/
main.cpp
File metadata and controls
74 lines (55 loc) · 1.51 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
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
/*
* File: main.cpp
* Author: btacklind
*
* Created on April 12, 2015, 9:37 PM
*/
#include <cstdlib>
#include <stdio.h>
#include <dirent.h>
#include "ProblemHandler.h"
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
if (argc != 2){
cout << argc << " Not right number of argument(s)" << endl;
exit(-1);
}
struct answers list [200];
int numAnswers = 0;
DIR *dir;
struct dirent *ent;
if ((dir = opendir (argv[1])) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
if (string(ent->d_name).find(".tsp") != -1){
string str = string(argv[1]).append("\\\\").append(ent->d_name);
//cout << ent->d_name << endl;
list[numAnswers++] = ProblemHandler::readFile(str.c_str());
}
}
closedir (dir);
} else {
/* could not open directory */
cout << "failed to open directory" << endl;
exit(-1);
}
cout << "Printing Answers" << endl;
for(int j = 0 ; j < numAnswers; j++){
if (!list[j].empty){
cout << list[j].name << ", " << list[j].HCP << ", " << list[j].shortPath;
string l;
int temp;
ifstream opt("OptimalTours.txt");
if(!opt.is_open()){
cout << "failed to open file" << endl;
}
while(getline(opt, l) && list[j].name.find(l.substr(0, (temp=l.find(":")) - 1)) == -1 );
cout << ", " << l.substr(temp+2) << endl;
opt.close();
}
}
return EXIT_SUCCESS;
}