-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanagram.cpp
More file actions
94 lines (77 loc) · 1.52 KB
/
anagram.cpp
File metadata and controls
94 lines (77 loc) · 1.52 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
94
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <math.h>
using namespace std;
int main (int argc, char **arg)
{
if (argc < 2)
{
cout << "Usage: anagram <word>\n";
return 0;
}
cout << "Input Word: " << arg[1] << "\n";
vector<int> prime;
for(int j=2;j<=101;++j)
{
int i=2;
for(;i<=j-1;i++)
{
if(j%i == 0)
break;
}
if(i==j)
prime.push_back(j);
}
cout << "(" << prime.size() << ") Anagram chars registered.\n";
int inword[strlen(arg[1])];
int inwordh = 1;
for (int i = 0; i < strlen(arg[1]); i++)
{
inword[i] = prime[arg[1][i] - 97];
inwordh *= inword[i];
cout << "->" << inwordh;
}
cout << "\n";
ifstream file("/usr/share/dict/words");
if (file.good())
{
cout << "Good Dictionary.\n";
} else
{
cout << "Bad Dictionary.\n";
}
cout << "----[Begin Results]----\n";
int size = 0;
string stdword;
while (file >> stdword)
{
char *word = &stdword[0u];
vector<char> dictword;
int dictwordh = 1;
for (int i = 0; i < strlen(word); i++)
{
if (word[i] < 97)
{
word[i] -= 32;
}
//Was going to implement a contains() to skip processing anything which didn't contain a letter which was present in the inword.
if(true)
{
dictword.push_back(prime[word[i] - 97]);
dictwordh *= dictword[i];
}
}
if (dictwordh == inwordh)
{
cout << word << "\n";
size++;
}
//dict.push_back(word);
}
cout << "-----[End Results]-----\n" << "Dictionary Size: [" << size <<
"]\n";
return 0;
}