program DFA_Min;
{$APPTYPE CONSOLE}
const
finame = 'c:\DFA_01_.txt';
foname = 'c:\DFA_01_MIN.txt';
var
fi,fo: TextFile;
Stat,NewStat: array of string;
Symb: array of char;
Table,NewTable: array of array of byte;
Equiv: array of array of byte;
Comps: array of longint;
flag,flag2: boolean;
i1,i2,i3,m,n,NStatCnt: longint;
ch: char;
st: string;
procedure Comp_DFS(op,cl: longint);
var
p1: longint;
begin
if Comps[op]<>0 then exit;
Comps[op]:=cl;
for p1:=0 to n-1 do if Equiv[op,p1]=0 then Comp_DFS(p1,cl);
end;
begin
{init}
AssignFile(fi,finame);
AssignFile(fo,foname);
Reset(fi);
Rewrite(fo);
//INPUT ---------------------------------------------------------------------
{statements}
Readln(fi,n);
SetLength(Stat,n);
for i1:=0 to n-1 do
begin
repeat Read(fi,ch) until ch<>' ';
Stat[i1]:=ch;
while NOT (EOLN(fi)) do
begin
Read(fi,ch);
if ch=' ' then break;
Stat[i1]:=Stat[i1]+ch;
end;
end;
Readln(fi);
{symbols}
Readln(fi,m);
SetLength(Symb,m);
for i1:=0 to m-1 do
begin
repeat Read(fi,ch) until ch<>' ';
Symb[i1]:=ch;
end;
Readln(fi);
{table}
SetLength(Table,n,m);
for i1:=0 to n-1 do
begin
for i2:=0 to m-1 do
begin
{input cell}
repeat Read(fi,ch); until ch<>' ';
st:=ch;
while NOT (EOLN(fi)) do
begin
Read(fi,ch);
if ch=' ' then break;
st:=st+ch;
end;
{find statement in list}
for i3:=0 to n-1 do if Stat[i3]=st then
begin
Table[i1,i2]:=i3;
break;
end;
end;
Readln(fi);
end;
//CREATE MINIMAL DFA --------------------------------------------------------
{check equivalence}
SetLength(Equiv,n,n);
flag:=true;
while flag do
begin
flag:=false;
for i1:=0 to n-2 do for i2:=i1+1 to n-1 do if Equiv[i1,i2]=0 then
begin
if (Stat[i1][1]='*') XOR (Stat[i2][1]='*') then
begin
Equiv[i1,i2]:=1;
Equiv[i2,i1]:=1;
flag:=true;
end
else
begin
flag2:=false;
for i3:=0 to m-1 do if (Equiv[Table[i1,i3],Table[i2,i3]]=1){ OR ((Stat[Table[i1,i3]][1]='*') XOR (Stat[Table[i2,i3]][1]='*')) }then
begin
flag2:=true;
break;
end;
if flag2 then
begin
Equiv[i1,i2]:=1;
Equiv[i2,i1]:=1;
flag:=true;
end;
end;
end;
end;
{components}
SetLength(Comps,n);
NStatCnt:=0;
for i1:=0 to n-1 do if Comps[i1]=0 then
begin
inc(NStatCnt);
Comp_DFS(i1,NStatCnt);
end;
{new stat}
SetLength(NewStat,NStatCnt);
for i1:=1 to NStatCnt do for i2:=0 to n-1 do
begin
if Comps[i2]=i1 then
begin
NewStat[i1-1]:=Stat[i2];
for i3:=i2+1 to n-1 do if Comps[i3]=i1 then if Stat[i3][1]<>'*' then NewStat[i1-1]:=NewStat[i1-1]+'+'+Stat[i3]
else NewStat[i1-1]:=NewStat[i1-1]+'+'+copy(Stat[i3],2,length(Stat[i3])-1);
break;
end;
end;
{new table}
SetLength(NewTable,NStatCnt,m);
for i1:=0 to NStatCnt-1 do for i2:=0 to m-1 do
begin
for i3:=0 to n-1 do if Comps[i3]=i1+1 then
begin
NewTable[i1,i2]:=Comps[Table[i3,i2]]-1;
break;
end;
end;
//OUTPUT---------------------------------------------------------------------
{statements}
Writeln(fo,NStatCnt);
for i1:=0 to NStatCnt-1 do Write(fo,NewStat[i1],' ');
Writeln(fo);
//Writeln(fo,nFinal);
{symbols}
Writeln(fo,m);
for i1:=0 to m-1 do Write(fo,Symb[i1],' ');
Writeln(fo);
{table}
for i1:=0 to NStatCnt-1 do
begin
for i2:=0 to m-1 do Write(fo,NewStat[NewTable[i1,i2]],' ');
Writeln(fo);
end;
{others}
while NOT (EOF(fi)) do
begin
Readln(fi,st);
Writeln(fo,st);
end;
{deinit}
CloseFile(fi);
CloseFile(fo);
end.
Перевести код с Delphi на С++
Код:
[COLOR="Red"]Оформляй код по правилам при помощи тегов.Что за названия темы ? "Очень срочно нужна помощь!!!" Замечание. [/COLOR]модератор.