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 submit program 20 times, but I get WA! Please help me or give some tests!++
Posted by Akshin Salimov 10 Apr 2005 20:41
I submit my program 20 times but I still get WA?
The problem is so simple but... I tried all tests written in the forum my program gives correct answer.

var
  a:array[1..10001] of char;
  ch:char;
  n:integer;
  skobka,comm:boolean;
  nsk:integer;
  i:integer;

procedure readdata;
begin
  n:=0;
  while not eof do
  begin
    inc(n);
    read(ch);
    a[n]:=ch;
  end;
end;

function check(ch:char):boolean;
begin
  if (ch in ['0'..'9']) or (ch in ['=','+','-','*','/']) then
  check:=true else check:=false;
end;

begin
  readdata;
  skobka:=false;
  comm:=false;
  for i:=1 to n do

  if (comm) and (a[i]='*') and (a[i+1]=')')  then
  begin
    comm:=false;
    inc(i);
  end         else

  if (not comm) and (a[i]='(') and (a[i+1]='*') then
  begin
    comm:=true;
    inc(i);
  end    else

  if comm then
  begin
  end          else

  if (not skobka) and (a[i]='(') then
  begin
    skobka:=true;
    nsk:=1;
  end            else

  if (skobka) and (a[i]=')') then
  begin
    dec(nsk);
    if nsk=0 then
    begin
      skobka:=false;
      nsk:=-maxint;
    end;
  end  else

  if (skobka) and (a[i]='(') then
  begin
    inc(nsk);
  end   else

  if ((skobka) and (not check(a[i]))) or
  ( (not skobka) and (a[i]='*') and (a[i+1]=')') and (not comm))
  then
  begin
    writeln('NO');
    halt;
  end  else

  if (nsk<0) and (nsk<>-maxint)then
  begin
    writeln('NO');
    halt;
  end;

  if (comm) or (skobka) then writeln('NO') else writeln('YES');
end.
Re: ++I submit program 20 times, but I get WA! Please help me or give some tests!++
Posted by Cybernetics Team 11 Apr 2005 15:11
On sample input yours outputs NO, correct is YES...
Re: ++I submit program 20 times, but I get WA! Please help me or give some tests!++
Posted by Akshin Salimov 11 Apr 2005 16:14
No, you are mistaken on sample test my program gives correct answer(YES)!