Por que arroja un resultado no desdeado?
Publicado por Federico (1 intervención) el 12/11/2017 22:45:56
LA LISTA DEL FINAL SIEMPRE ARROJA SOLO UN VALOR AUN EN CASOS DONDE DEBE ARROJAR MAS DE UNO.
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
132
133
134
135
136
137
138
139
140
141
procedure ArrClaves(entrada : TipoTexto ; pal : TipoPalabra ; var claves : ArrayClaves );
var
i, j, k, cl, cl2, cont, y: integer;
encontrado : boolean;
begin
claves.tope := 0;
cont := 0;
y := 0;
encontrado := false;
if entrada.texto[1] <> ' ' then {Viendo el caso borde en el que la primera palabra sea la buscada}
begin
cont := cont + 1;
j := 1;
k := 1;
cl := (ord(entrada.texto[j]))-(ord(pal.palabra[k]));
if cl < 0 then
begin
cl2 := cl;
cl := cl + 26
end
else
cl2 := cl - 26;
j := j + 1;
k := k + 1;
while (k <= pal.tope) and (j <= entrada.tope) and (((ord(entrada.texto[j]))-(ord(pal.palabra[k])) = cl) or ((ord(entrada.texto[j]))-(ord(pal.palabra[k])) = cl2)) do
begin
j := j + 1;
k := k + 1;
end;
if (k > pal.tope) and ((j > entrada.tope) or (entrada.texto[j] = ' ')) then
begin
cl := cl - (cont - 1);
if cl < 0 then
cl := cl + 26;
y := y + 1;
claves.clave[y] := cl;
claves.tope := claves.tope + 1;
end;
end;
for i := 2 to entrada.tope do
begin
if (entrada.texto[i] <> ' ') and (entrada.texto[i-1] = ' ') then
begin
j := i;
k := 1;
cont := cont + 1;
cl := (ord(entrada.texto[j]))-(ord(pal.palabra[k]));
if cl < 0 then
begin
cl2 := cl;{Uso cl y cl2 para tener los casos de que la resta de negativa o positiva teniendo el mismo desplazamiento}
cl := cl + 26
end
else
cl2 := cl - 26;
j := j + 1;
k := k + 1;
while (k <= pal.tope) and (j <= entrada.tope) and (((ord(entrada.texto[j]))-(ord(pal.palabra[k])) = cl) or ((ord(entrada.texto[j]))-(ord(pal.palabra[k])) = cl2)) do
begin
j := j + 1;
k := k + 1;
end;
if (k > pal.tope) and ((j > entrada.tope) or (entrada.texto[j] = ' ')) then
encontrado := true;
end;
if encontrado then
begin
cl := cl - (cont - 1);
if cl < 0 then
cl := cl + 26;
y := y + 1;
claves.tope := claves.tope + 1;
claves.clave[y] := cl;
end;
encontrado := false
end;
end;
procedure eliminarIguales(var claves : ArrayClaves);
var
i, j, ult, aux : integer;
begin
for i := 1 to claves.tope do
for j := i + 1 to claves.tope do
begin
if claves.clave[i] = claves.clave[j] then
begin
ult := claves.tope;
aux := claves.clave[ult];
claves.clave[ult] := claves.clave[j];
claves.clave[j] := aux;
claves.tope := claves.tope - 1;
end;
end;
end;
procedure ordenar(var claves : ArrayClaves);
var
i, j, aux : integer;
begin
for i := 2 to claves.tope do
begin
j := i;
while (j >= 2) and (claves.clave[j] < claves.clave[j-1]) do
begin
aux := claves.clave[j];
claves.clave[j] := claves.clave[j-1];
claves.clave[j-1] := aux;
end;
end;
end;
function PosiblesClaves(palabra: TipoPalabra; texto : TipoTexto) : ListaClaves;
var
i : integer;
cs : ArrayClaves;
l, p : ListaClaves;
begin
new(l);
p := l ;
ArrClaves(texto,palabra,cs);
if cs.tope > 0 then
begin
if cs.tope > 1 then
begin
eliminarIguales(cs);
if cs.tope > 1 then
ordenar(cs);
end;
for i := 1 to cs.tope do
begin
p^.clave := cs.clave[i];
p := p^.sig;
new(p);
end;
dispose(p);
p := NIL
end
else
begin
dispose(l);
l := NIL;
end;
PosiblesClaves := l
end;
Valora esta pregunta


0