Nor can I solve it by Dp.
const
Inf ='';
Outf ='';
max =10;
var
n :integer;
Procedure main;
var
i,j,k :integer;
s,bool :string[max+2];
alp :set of char;
c :char;
begin
assign(input,Inf); reset(inpuT);
assign(output,Outf); rewrite(output);
readln(n);
alp:=['p','u','t','o','i','n','e'];
for i:=1 to n do
begin
k:=0;
s:='';
bool:='1';
while not(eoln) do
begin
if length(s)>max then begin delete(s,1,1); delete(bool,1,1); end;
read(c);
if not(c in alp) then begin bool:='0'; break; end;
s:=s+c;
if (c='n') and (length(s)>1) then if (copy(s,length(s)-1,2)='in') and (bool[length(bool)-1]='1')
then begin bool:=bool+'1'; continue end;
if (c='n') and (length(s)>4) then if (copy(s,length(s)-4,5)='puton') and (bool[length(bool)-4]='1')
then begin bool:=bool+'1'; continue end;
if (c='t') and (length(s)>2) then if (copy(s,length(s)-2,3)='out') and (bool[length(bool)-2]='1')
then begin bool:=bool+'1'; continue end;
if (c='t') and (length(s)>4) then if (copy(s,length(s)-4,5)='input') and (bool[length(bool)-4]='1')
then begin bool:=bool+'1'; continue end;
if (c='t') and (length(s)>5) then if (copy(s,length(s)-5,6)='output') and (bool[length(bool)-5]='1')
then begin bool:=bool+'1'; continue end;
if (c='e') and (length(s)>2) then if (copy(s,length(s)-2,3)='one') and (bool[length(bool)-2]='1')
then begin bool:=bool+'1'; continue end;
bool:=bool+'0';
end;
if bool[length(bool)]='1' then writeln('YES')
else writeln('NO');
readln(s);
end;
close(output);
close(Input);
end;
begin
main;
end.
If I use Pascal,I found the "read" takes too long time.In C,we can use "getc".But in pascal,I don't know how to do.
Is there any algo better than Dp? What does DFA meant?
Could you give me some hint or a good algo?
Thanks for your help.
Waiting for RE.