(мне нужно найти в первом предложении самое короткое слово,которого нет во втором)
Код
const
lim=[#0..#32,'.',',',':',';','!','?','"','+'];
type
Twords=array[1..40] of string;
var
i,j,k,n1,n2,nmin,h:byte;
w1,w2:Twords;
function GWords(p:string;var w:Twords):byte;
var
i,b,n:byte;
begin
i:=1;
n:=0;
while (i<=length(p)) do begin
while (i<=length(p)) and (p[i] in lim) do
inc(i);{+1}
if i<=length(p) then begin
b:=i;
while (i<=length(p)) and not(p[i] in lim) do
inc(i);
inc(n);
w[n]:=copy(p,b,i-b);
end;
end;
GWords:=n;
end;
begin
n1:=GWords(p1,w1);//ñîáèðàåì â ìàññèâ ñëîâà 1 ïðåäëîæåíèÿ
n2:=GWords(p2,w2);//ñîáèðàåì â ìàññèâ ñëîâà 2 ïðåäëîæåíèÿ
//óäàëÿåì èç ïåðâîãî ìàññèâà ñëîâà,êîòîðûå åñòü âî âòîðîì
i:=1;
while (i<=n1) do begin
j:=1;
while (j<=n2) and (AnsiLowerCase(w1[i])<>AnsiLowerCase(w2[j])) do inc(j);
if j<=n2 then begin
for k:=i to pred(n1) do
w1[k]:=w1[succ(k)];
dec(n1);//n1-1
end
else inc(i);//i+1
end;
//èùåì ñàìîå êîðîòêîå ñëîâî èç îñòàâøèõñÿ
nmin:=0;
if n1>0 then begin
nmin:=1;
for i:=2 to n1 do
if w1[i]<w1[nmin] then begin
nmin:=i;
memo1.Lines.append(w1[nmin]);
end;
end;
end;
lim=[#0..#32,'.',',',':',';','!','?','"','+'];
type
Twords=array[1..40] of string;
var
i,j,k,n1,n2,nmin,h:byte;
w1,w2:Twords;
function GWords(p:string;var w:Twords):byte;
var
i,b,n:byte;
begin
i:=1;
n:=0;
while (i<=length(p)) do begin
while (i<=length(p)) and (p[i] in lim) do
inc(i);{+1}
if i<=length(p) then begin
b:=i;
while (i<=length(p)) and not(p[i] in lim) do
inc(i);
inc(n);
w[n]:=copy(p,b,i-b);
end;
end;
GWords:=n;
end;
begin
n1:=GWords(p1,w1);//ñîáèðàåì â ìàññèâ ñëîâà 1 ïðåäëîæåíèÿ
n2:=GWords(p2,w2);//ñîáèðàåì â ìàññèâ ñëîâà 2 ïðåäëîæåíèÿ
//óäàëÿåì èç ïåðâîãî ìàññèâà ñëîâà,êîòîðûå åñòü âî âòîðîì
i:=1;
while (i<=n1) do begin
j:=1;
while (j<=n2) and (AnsiLowerCase(w1[i])<>AnsiLowerCase(w2[j])) do inc(j);
if j<=n2 then begin
for k:=i to pred(n1) do
w1[k]:=w1[succ(k)];
dec(n1);//n1-1
end
else inc(i);//i+1
end;
//èùåì ñàìîå êîðîòêîå ñëîâî èç îñòàâøèõñÿ
nmin:=0;
if n1>0 then begin
nmin:=1;
for i:=2 to n1 do
if w1[i]<w1[nmin] then begin
nmin:=i;
memo1.Lines.append(w1[nmin]);
end;
end;
end;