-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
93 lines (90 loc) · 2.2 KB
/
main.cpp
File metadata and controls
93 lines (90 loc) · 2.2 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// main.cpp : Defines the entry point for the application.
//
#include "WordList.h"
#include <filesystem>
#include <chrono>
using namespace std;
namespace fs = std::filesystem;
int main()
{
constexpr std::string_view def_path = R"(C:\Dev\enable.txt)";
WordList word_list;
cout << "Enter the file name for word list:" << endl;
string path;
cin >> path;
if (fs::exists(path) && fs::is_regular_file(path))
{
word_list.setFileName(path);
}
else
{
cout << "Invalid path, use default "<<def_path << endl;
word_list.setFileName(string(def_path));
}
auto start = std::chrono::high_resolution_clock::now();
bool status = word_list.load();
auto end = std::chrono::high_resolution_clock::now();
if (!status)
{
cout << "Failed to load the word list" << endl;
return 1;
}
std::chrono::duration<double, std::milli> duration = end - start;
std::cout << "Load execution time: " << duration.count() << " ms\n";
word_list.printMemoryUsage();
bool one_more = true;
while (one_more)
{
bool valid = false;
int option;
while (!valid)
{
cout << endl;
cout << "Choose the option (press 1/2/3):" << endl;
cout << "1: Enter words to find a transform between (words would be added to the word list if it didn't contain them)" << endl;
cout << "2: Generate transform between 2 random words of the same length from existing ones in the word list (repeated till success)" << endl;
cout << "3: Exit the program" << endl;
cin >> option;
if (option == 1 || option == 2 || option == 3)
valid = true;
}
if (option == 1)
{
string a, b;
cout << "Enter the first word:" << endl;
cin >> a;
cout << "Enter the second word:" << endl;
cin >> b;
StringList result = word_list.findTransform(a, b);
for (int i = 0; i < result.size(); ++i)
{
cout << result[i];
if (i < result.size() - 1)
cout << " -> ";
else
cout << endl;
}
}
else if (option == 2)
{
StringList result;
while (result.empty())
{
result = word_list.findRandomTransform();
}
for (int i = 0; i < result.size(); ++i)
{
cout << result[i];
if (i < result.size() - 1)
cout << " -> ";
else
cout << endl;
}
}
else
{
one_more = false;
}
}
return 0;
}