-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·131 lines (127 loc) · 2.99 KB
/
main.cpp
File metadata and controls
executable file
·131 lines (127 loc) · 2.99 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <iostream>
#include <stdint.h>
#include "hash_table.h"
using namespace std;
void checkword(string input, hash_table *table);
int main()
{
hash_table tabela;
bool keep_going = true;
string in,last;
last = "-";
uint8_t i;
while(keep_going)
{
cin >> in;
for (i = 0; i < in.length(); i++)
in[i] = tolower(in[i]);
if (in.compare("+") == 0)
{
if (last.compare("-") != 0 && tabela.add(last))
cout << "ok" << endl;
else
cout << "fail" << endl;
}
else if (last.compare("-") != 0 && in.compare("-") == 0)
{
if (tabela.del(last))
cout << "ok" << endl;
else
cout << "fail" << endl;
}
else if (in.compare("*") == 0)
{
keep_going = false;
}
else
{
if (tabela.locate(in))
cout << "ok";
else
checkword(in, &tabela);
last.assign(in);
cout << endl;
}
if (!cin.good())
keep_going = false;
}
return 0;
}
void checkword(string input, hash_table *table)
{
uint32_t i;
uint32_t qnt=0;
char j;
string temp;
linked_list testes;
linked_list correcoes;
for (i = 0; i < input.length(); i++) //testa por palavras fornecidas com uma letra a mais
{
temp.assign(input);
temp.erase(i,1);
testes.add(temp);
}
for (i = 0; i < input.length(); i++) //testa por palavras fornecidas com uma letra a menos
{
temp.assign(input);
temp.insert(i,1,'a');
for (j = 'b'; j <= 'z'; j++)
{
temp[i] = j;
testes.add(temp);
}
if (i > 0)
{
temp[i] = '-';
testes.add(temp);
}
}
temp.assign(input);
temp.append(1,'a');
for (j = 'b'; j <= 'z'; j++)
{
temp[i+1] = j;
testes.add(temp);
}
temp.assign(input);
for (i = 0; i < input.length()-1; i++) //testa por letras trocadas;
{
temp[i]=input[i+1];
temp[i+1]=input[i];
testes.add(temp);
temp[i]=input[i];
temp[i+1]=input[i+1];
}
temp.assign(input);
for (i = 0; i < input.length(); i++) //testa por uma letra errada
{
char tempc = temp[i];
for (j = 'a'; j <= 'z'; j++)
{
temp[i] = j;
testes.add(temp);
}
if (i > 0)
{
temp[i] = '-';
testes.add(temp);
}
temp[i] = tempc;
}
qnt = testes.tam();
for (i = 0; i < qnt; i++)
{
temp.assign(testes.decapitate());
if (table->locate(temp))
correcoes.adds(temp);
}
qnt = correcoes.tam();
if ( qnt > 0)
{
cout << correcoes.decapitate();
for (i = 1; i < qnt; i++)
cout << " " << correcoes.decapitate();
}
else
cout << "not found";
}