Could you tell us what reply you get? Btw, you can nicely indent your code (see FAQ). That way it's easier for us to read... If you want to, you can even do it afterwards by editing your posting. I like the new forum
<font size=-1>[ This Message was edited by: Stefan Pochmann on 2002-03-19 11:40 ]</font>
I've got the same problem like ahanys...
My program runs (I think OK) with rules, which have empty sides (before or after a production sign), I consider also that empty string belongs to words generated by G (I try with case, that empty string doesn't belong but WA too).
Could anyone tell me, what should be wrong? Or send me some IO or maybe I can send (s)he my code ? It's similar to code ahanys ...
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Per: Could you help me ? I've got correct results for your inputs, but judge says TLE. I don't know what can I do wrong ... Can I send you my code via PM ?
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Thanks Per again. I didn't think about such kind of productions before ...
For every, who has problems with this question:
think about productions like "a"->"aaa"
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
var
GRAMS:array [1..100] of Grammer;
LWords:Array [1..1000] of string;
lines,GRAMSCNT:integer;
Language:string;
WCnt:integer;
function IsValid(Word:string):boolean;
var
r:boolean;
i:integer;
begin
r:=true;
for i:=1 to WCnt do
begin
if LWords=Word then r:=false;
end;
IsValid:=r;
end;
procedure Words(st:integer;var lang:string;var Count:integer);
var
TLang:string;
i,j:integer;
begin
if Count<=1000 then
begin
for j:=st to length(lang) do
begin
for i:=1 to GRAMSCNT do
begin
if(copy(lang,j,length(GRAMS.Src))=GRAMS.Src) then
begin
TLang:=lang;
lang:=copy(lang,1,j-1)+GRAMS.Des +copy(lang,j+length(GRAMS.Src),length(lang));
if (IsValid(lang)) then
begin
Count:=Count+1;
LWords[Count]:=lang;
Words(i+length(GRAMS.Src),lang,Count);
end;
lang:=Tlang;
if Count>1000 then Break;
end;
end;
if Count>1000 then Break;
end;
end;
end;
procedure READGRAMS();
var
TMPSTR:string;
i,pre,state:integer;
begin
readln(TMPSTR);
while(TMPSTR<>'') do
begin
pre:=-1;
state:=1;
for i:=1 to length(TMPSTR) do
if TMPSTR='"' then
if pre<>-1 then
begin
if state=1 then
begin
GRAMSCNT:=GRAMSCNT+1;
GRAMS[GRAMSCNT].Src:=copy(TMPSTR,pre,i-pre);
GRAMS[GRAMSCNT].Des:='';
state:=2;
end
else
GRAMS[GRAMSCNT].Des:=copy(TMPSTR,pre,i-pre);
if GRAMS[GRAMSCNT].Des=GRAMS[GRAMSCNT].Src then
begin
GRAMSCNT:=GRAMSCNT-1;
end;
pre:=-1;
end
else
pre:=i+1;
readln(TMPSTR);
end;
end;
begin
readln(lines);
readln;
while(lines>0) do
begin
readln(Language);
if Language ='' then Break;
Language:=copy(Language,2,length(Language)-2);
GRAMSCNT:=0;
READGRAMS();
WCnt:=1;
LWords[WCnt]:=Language ;
Words(1,Language,WCnt);
if(WCnt>1000) then
writeln('Too many.')
else
writeln(WCnt);