uses crt;
const
delimiters=[' ','.',',',';','!','?',':','*','#','$','(',')','[',']'];
type
TDirections=(ReadFile,WriteFile);
ArrString=array [1..10] of string;
ArrBuf=array [1..1024] of byte;
function OpenNonTypicalFile (buf: ArrBuf; var F: file; FileName: string; Direction: TDirections): boolean;
var Result: boolean;
begin
assign(F,FileName);
Result:=True;
case Direction of
ReadFile: Reset(F,sizeof(F));
WriteFile: ReWrite(F,sizeof(F));
end;
if IOResult<>0 then
begin
case Direction of
ReadFile: writeln('Failed to read file '+FileName);
WriteFile: writeln('Failed to write file '+FileName);
end;
Result:=False;
end;
OpenNonTypicalFile:=Result;
end;
function ReadNonTypicalFile (buf: ArrBuf; var F: file; d: string): string;
begin
while not eof(F) do
begin
BlockRead(F,buf,sizeof(d),d);
end;
ReadNonTypicalFile:=d;
end;
function FirstIndex (s: string; var i: byte): byte;
begin
while (s[i] in delimiters) do
inc(i);
FirstIndex:=i;
end;
function LastIndex (s: string; i: byte): byte;
begin
while not(s[i] in delimiters) do
inc(i);
LastIndex:=i-1;
end;
function GetWord (s: string; b,e: byte): string;
begin
GetWord:=copy(s,b,e-b+1);
end;
var
i, j, s, FI, LI, l, wordbeg, iel: byte;
line, el: string;
a: ArrString;
buf: ArrBuf;
F: file;
begin
clrscr;
if OpenNonTypicalFile(buf,F,'111.dat',ReadFile) then
line:=ReadNonTypicalFile(buf,F,el);
wordbeg:=1;
i:=1;
s:=0;
begin
l:=length(line);
while wordbeg<l+1 do
begin
FI:=FirstIndex(line,wordbeg);
LI:=LastIndex(line,FI);
writeln(GetWord(line,FI,LI));
a[i]:=GetWord(line,FI,LI);
inc(i);
s:=s+1;
wordbeg:=LI+1;
end;
end;
if OpenNonTypicalFile(buf,F,'112.dat',WriteFile) then
for i:=1 to s do
begin
el:=a[i];
iel:=i;
for j:=1 to s do
if (a[j]=el) and (not(j=iel)) then
a[j]:='';
end;
for i:=1 to s do
BlockWrite(F,buf,sizeof(a[i]),a[i]);
close(F);
end.
типированный файл |