we are doing pascal in school and task is to get all words with only latin chars which have descendingly alphabetical order in those words. So I input "sba dcb onml dfsf cba kl2 joh;" and programm has as output "sba dcb onml dfsf cba" which is mostly right but I cant udnerstand why it contains "dfsf" and how can I fix it? P.S.: Sorry for my english.
var
u: string;
ws: array[1..100] of string;
w: string;
len: integer;
i, j, q, t, a, b, n, s, z: integer;
begin
writeln('type string:');
read(u);
len := length(u);
a := 1;
i := 1;
s := 1;
while i <= len do
if (u[i] >= '!') and (u[i] <= '~') then begin
w := u[i];
i := i + 1;
while (i <= len) and
((u[i] >= '!') and
(u[i] <= '~')) do begin
w := w + u[i];
i := i + 1;
for t := 1 to length(w) do begin
if not (w[t] in ['a'..'z']) then begin
s:= 0;
Break;
end else begin
s:= s + 1;
n:=length(w);
for a:=1 to n-1 do
for b:=a+1 to n do
if not (w[a] >= w[b]) then
begin
s:=0;
end else begin
s:= s + 1;
end;
end;
end;
end;
if s<>0 then begin
q:= q + 1;
ws[q] := w;
end;
end
else
i := i + 1;
for i := 1 to q do
writeln(ws[i]);
end.