program
Lab41;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
tbookword=
record
w:
string
;
wasfound:
boolean
;
end
;
tbookdata=
array
of
tbookword;
var
s:
string
;
w:
string
;
i:
integer
;
st:
string
;
tb:tbookdata;
function
loadbook:tbookdata;
var
f:text;
z:
string
;
begin
result:=
nil
;
assignfile(f,
'E:\Labs\Кодировочная книга.txt'
);
reset(f);
while
not
Eof(f)
do
begin
readln(f,z);
SetLength(result,Length(result)+
1
);
result[length(result)-
1
].w:=z;
result[length(result)-
1
].wasfound:=
false
;
end
;
closeFile(f);
end
;
function
number_of_word(w:
string
;
var
tb:tbookdata):
integer
;
var
lastfound, i:
integer
;
begin
result:=-
1
;
lastfound:=-
1
;
for
i :=
0
to
length(tb)-
1
do
begin
if
(tb[i].w=w)
then
begin
if
(result<
0
)
and
(
not
tb[i].wasfound)
then
begin
result:=i;
tb[i].wasfound:=
true
;
end
;
lastfound:=i;
end
;
end
;
if
result>=
0
then
begin
if
result=lastfound
then
for
i :=
0
to
length(tb)-
1
do
if
tb[i].w=w
then
tb[i].wasfound:=
false
;
result:=result+
1
;
end
;
end
;
begin
writeln
(
'vvedite text :'
);
readln(s);
i:=
1
;
st:=
''
;
tb:=loadbook;
while
i<=length(s)
do
begin
while
(i<=length(s))
and
(s[i]=
' '
)
do
i:=i+
1
;
w:=
''
;
while
(i<=length(s))
and
(s[i]<>
' '
)
do
begin
w:=w+s[i];
i:=i+
1
;
end
;
if
w<>
''
then
begin
st:=st+IntToStr(number_of_word(w,tb)) +
' '
;
end
;
end
;
writeln
(
' close text:'
, st);
readln;
end
.