|
|
back to boardI got WA. Please check it. Thanks! 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. |
|
|