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 got WA. Please check it. Thanks!
Posted by SunMoonStar 24 Jan 2003 11:59
program p1027;
const expppp:set of char=['0'..'9','=','+','-','*','/','(',')'];
var brackets,i,comment:integer; comm,expr:boolean; line:string;

{$APPTYPE CONSOLE}

procedure sout(st:string);
begin
     WRITELN(st); halt;
end;

begin
     expr:=false; comm:=false; brackets:=0; comment:=0;
     while not eof do
       begin
         readln(line); i:=1;
         while (i<=length(line)) do
           begin
             if (line[i]='(') then
               begin
                 if (line[i+1]='*') then
                   begin
                     if (line[i+2]<>')') or (not comm) then
                       begin
                         if (comment=0) then comm:=true;
                         inc(i); inc(comment);
                       end;
                   end else
                   begin
                     if (brackets=0) and (not comm) then expr:=true;
                     if (not comm) then inc(brackets);
                   end;
               end else
             if (line[i]=')') and (not comm) then
               begin
                 if (brackets=1) then expr:=false;
                 if (not comm) then dec(brackets);
               end else
             if (line[i]='*') and (line[i+1]=')') and comm then
               begin
                 if (comment=1) then comm:=false; inc(i); dec
(comment);
               end;
             if (line[i]=' ') and expr and (not comm) then sout
('NO');
             if expr and (not comm) and not (line[i] in expppp) then
sout('NO');
             if (brackets<0) or (comment<0) then sout('NO');
             inc(i);
           end;
       end;
     if (brackets<>0) or (comment<>0) then sout('NO');
     sout('YES');
end.