|
|
back to boardWho can tell me (()) is right or wrong? Thank you. But how about () and (* *) *)? Thank you again. But I still get WA, and need some help... I don't know what's wrong with my program. Is there any point I didn't conside? Here is my program, could you give me some hint or some test data? const MaxSize=10005; var word:array[1..MaxSize] of char; Top,Cur:integer; C:char; Error:boolean; procedure comment; var b:boolean; begin b:=true; inc(cur); while (cur<top) and b do begin if (word[cur]='*') and (word[Cur+1]=')') then b:=false else inc(cur); end; if not b then inc(cur) else error:=true; end; procedure expression; var b:boolean; T:integer; begin inc(Cur); if (Cur>Top) then begin Error:=true; exit; end; if word[Cur]='*' then begin Comment; exit; end; T:=1; while (Not error) and (Cur<=Top) and (T>0) and (word[Cur] in ['+','-','*','/','0'..'9','(',')','=']) do begin if (word[cur]='(') and (word[cur+1]<>'*') then begin b:=true; T:=T+1; end; if (word[cur]<>'(') and (word[cur]<>')') then b:=true; if (word[Cur]=')') then T:=T-1; if (word[Cur]='(') and (word[Cur+1]='*') then begin inc(cur); comment; end; if T<>0 then inc(cur); end; if T<>0 then error:=true; end; begin Top:=0; read(c); while not eof do begin if (ord(c)<>13) and (ord(C)<>10) and (ord(c)<>0) then begin inc(Top); word[top]:=c; end; read(c); end; Cur:=1; Error:=false; Word[Top+1]:=' '; while (Not Error) and (Cur<=Top) do begin if word[Cur]='(' then Expression else if word[Cur]=')' then error:=true; inc(Cur); end; if Not error then writeln('YES') else writeln('NO');end. |
|
|