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

I don't belive my cole get WA.plz help.
Posted by Ural_Happy New Year! 26 May 2003 18:38
program t1027;
{const fin='f:\temp\in4.txt';}
var i,j,pp,n,k:longint;
    ch:char;
    str:array[1..10000] of char;
    t,tt:boolean;
begin
{     assign(input,fin);
     reset(input);}
     j:=1;
     while not (ch=#26) do
           begin
           read(ch);
           str[j]:=ch;
           inc(j);
           end;
     n:=j-1; i:=0;
     repeat
         inc(i);
         j:=i;
         if str[i]='(' then
            if str[i+1]='*' then
               begin
                    t:=false;
                    for j:=i+2 to n do if (str[j]='*')and(str[j+1]
=')') then
                        t:=true;
                    if t=false then begin writeln('NO'); tt:=false;
halt; end
                       else i:=j+2;
                    j:=0;
               end
            else begin
                 pp:=1;
                 repeat
                       inc(j);
                       if not(str[j] in ['(',')','0'..'9','+','-
','*','/','='])
                          then begin writeln('NO'); tt:=false; halt;
end;
                       if (str[j]='*')and(str[j-1]='(') then
                          begin
                          dec(pp);
                          for k:=j+1 to n do
                              if (str[k]='*')and(str[k+1]=')') then
                                 begin j:=k+2; break; end;
                          if k>=n then begin writeln('NO');
tt:=false; halt; end;
                          end;
                       if str[j]=')' then dec(pp);
                       if pp=0 then break;
                       if str[j]='(' then inc(pp);
                 until j>=n;
                 if pp<>0 then begin writeln('NO'); tt:=false; halt;
end;
                 i:=j+1;
                 end;
     until i>=n;
     if tt then writeln('YES');
{     close(input);}
end.