-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.cpp
42 lines (42 loc) · 1.17 KB
/
runner.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
#include "crossword.h"
#include <fstream>
using namespace std;
#define input(msg, var){ cout << msg; cin >> var;}
STRINGS load_words(string file_name){
ifstream words_file(file_name);
STRINGS words;
string buffer;
while(getline(words_file, buffer))
words.push_back(buffer);
words_file.close();
return words;
}
// template<typename type> void input(string msg, type& var){ cout << msg; cin >> var; }
int main(int argc, char **argv)
{
string crossword_filename, words_filename;
size_t height;
if(argc == 1){
input("Crossword height = ", height);
input("Crossword text file: ", crossword_filename);
input("Words' text file: ", words_filename);
}
else if(argc == 4){
height = stoi(argv[1]);
crossword_filename = argv[2];
words_filename = argv[3];
}
else{
cout << "Usage: [crossword.exe] [heigth] [crossword.txt] [words.txt]\n";
return 0;
}
crossword cw('-', '#', height);
ifstream cwfile(crossword_filename);
cwfile >> cw;
cwfile.close();
auto domain = load_words(words_filename);
cw.set_domain(domain);
cw.solve();
cout << cw;
return 0;
}