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

help me! What's wrong with my program?
Posted by lyj_george 21 Nov 2001 17:14
var
  m : array [1..10000] of char;
  ch : char;
  lk , rk : integer;
  kin : boolean;
  tot ,step: integer;
procedure wrong;
begin
  writeln('NO');
  halt;
end;
begin
  tot := 0;
  repeat
    read(ch);
    inc(tot);
    m[tot] := ch;
  until ch = #26;
  step := 0;
  lk := 0;
  rk := 0;
  while step < tot do begin
    inc(step);
    if (m[step]='(') then begin
      if m[step+1] = '*' then begin
        step := step + 1;
        repeat
          inc(step);
          if step > tot then wrong;
        until (m[step]=')') and (m[step-1]='*');
        continue;
      end else inc(lk);
    end;
    if (m[step]=')') then inc(rk);
    if lk < rk then wrong;
    if (lk > rk) and not (m[step] in ['0'..'9','+','-
','*','/','=','(',')',#10,#13]) then wrong;
  end;
  if lk <> rk then wrong;
  writeln('YES');
end.



You need to change only one symbol :)
Posted by shitty.Mishka 21 Nov 2001 20:25
Firstly, you might get "Compilation error" because of this
line:
    if (lk > rk) and not (m[step] in ['0'..'9','+','-
','*','/','=','(',')',#10,#13]) then wrong;, you better
make it shorter.
But the main thing is that your program outputs 'YES' for
this test case:
(*)
But it's, obviously wrong. So, there's only one symbol you
have to change to get AC (by the way, you can be sure you
will:)
Re: help me! What's wrong with my program?
Posted by zhangyyy 11 Jan 2002 05:40
>step:=step+1--->step:=step+2