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

And this is my code

program ural1027;
const   ll='(*';
        rr='*)';

type    ts=ansistring;
var     s:ts;

procedure rd;
var     ch:char;
begin
 s:='';
 while not eof do
  begin
   read(ch);
   if (ch<>#13) and (ch<>#10) then s:=s+ch;
  end;
end;

procedure print(i:integer);
begin
 case i of
 0: write('NO');
 1: write('YES');
 end;
 halt;
end;

procedure dellr(var s:ts);
var  i,p,l:integer;


begin
 p:=pos(ll,s);
 l:=length(s);
 while p<>0 do
  begin
   i:=p+3;

   while (i<=l) and not ((s[i]=')') and (s[i-1]='*'))
    do inc(i);

   if (i>l) or (i=p+2) then print(0);

   delete(s,p,i+1-p);

   if s='' then print(1);
   p:=pos(ll,s);
   l:=length(s);
  end;

end;

procedure solve(s:ts);
var     p:integer;
        t:ts;
        ss:string;

 function cannot(t:ts):boolean;
 var    i,tot:integer;

 begin
  tot:=0;

  for i:=1 to length(t) do
   begin
    if s[i]='(' then inc(tot)
     else if s[i]=')' then dec(tot)
      else
       begin
        if not (s[i] in ['=','+','-','*','/','0'..'9',')','('])
            then exit(true);
       end;

    if tot<0 then exit(true)
     else if (tot>0) and (s[i]=' ') then exit(true);

   end;
  if tot<>0 then exit(true)
   else exit(false);
 end;

begin
 s:=s+' ';

 while s[1]=' ' do delete(s,1,1);
 p:=pos(' ',s);

 while (s<>'') and (p<>0) do
  begin

   t:=copy(s,1,p-1);
   if (pos('(',t)<>0) or (pos(')',t)<>0)
    then if cannot(t) then print(0);
   delete(s,1,p);

   while (s<>'') and (s[1]=' ') do delete(s,1,1);
   if s='' then break;
   p:=pos(' ',s);
  end;
end;

begin

 rd;

 dellr(s);
 solve(s);
 print(1);

end.


and if i remove the sentence
" if not (s[i] in ['=','+','-','*','/','0'..'9',')','('])
            then exit(true);"
I'll get WA#9

Who Can Tell Me WHY~~~~

Edited by author 27.10.2009 16:17
Bunyodbek Bobodjanov (TATU UF) Re: I've try many times , but stil WA#1 WHO CAN HELP ME!! [3] // Problem 1027. D++ Again 27 Oct 2009 15:51
I think You should read it with the help of EndofLine or Readln.
Bunyodbek Bobodjanov (TATU UF) Re: I've try many times , but stil WA#1 WHO CAN HELP ME!! [2] // Problem 1027. D++ Again 27 Oct 2009 15:52
Sorry EndofFile
 s:='';
 while not eof do
  begin
   read(ch);
   if ch>=' ' then s:=s+ch;
   if eoln then readln;
  end;

I change it like this
 but still WA#1, can you tell me how to read it correctly
You should

read(ch)
check if not eof
 and only then doing s:=s+ch;
          else break;