I've try many times , but stil WA#1 WHO CAN HELP ME!!
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
Re: I've try many times , but stil WA#1 WHO CAN HELP ME!!
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
Re: I've try many times , but stil WA#1 WHO CAN HELP ME!!
Posted by
melkiy 27 Oct 2009 17:06
You should
read(ch)
check if not eof
and only then doing s:=s+ch;
else break;