ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1027. D++ Again

Who can tell me (()) is right or wrong?
Posted by Song Chao (ECUST Mutistar) 5 Apr 2002 16:24
It's right
Posted by MadPsyentist/Sam 5 Apr 2002 19:17
>
Thank you. But how about () and (* *) *)?
Posted by Song Chao (ECUST Mutistar) 7 Apr 2002 19:08
YES and NO respectively
Posted by MadPsyentist/Sam 8 Apr 2002 01:39
>
Thank you again. But I still get WA, and need some help...
Posted by Song Chao (ECUST Mutistar) 8 Apr 2002 14:51
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.