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 1297. Palindrome

Why I got WA#2? Program is here, I'm sure my alg is correct!!!
Posted by Akshin 8 Apr 2005 21:38
Plz help me, or give some test.

var
  st:array[1..1000] of integer;
  b,e,i,j,k,m,max,n,ist:integer;
  a:array[1..1000] of char;
  ch:char;

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

procedure writedata;
begin
  for i:=b to e-1 do
  write(a[i]); writeln(a[e]);
end;

procedure push(x:integer);
begin
  st[ist]:=x;
  inc(ist);
end;

procedure pop(var x:integer);
begin
  dec(ist);
  x:=st[ist];
  st[ist]:=0;
end;

begin
  readdata;
  max:=0; ist:=1;
  for i:=1 to n-1 do
  begin
    j:=i;
    if (ist>=2) and (a[j]=a[st[ist-1]]) then
    begin
      k:=0; m:=ist-1;
      while (j<=n) and (m>=1) and (a[j]=a[st[m]]) do
      begin
        inc(j);
        dec(m);
        inc(k);
      end;
      k:=k*2;
      if k>max then
      begin
        max:=k;
        b:=m+1;
        e:=j-1;
      end;
      push(i);
    end                    else

    if (ist>=2) and (a[j+1]=a[st[ist-1]]) then
    begin
      inc(j);
      k:=0; m:=ist-1;
      while (j<=n) and (m>=1) and (a[j]=a[st[m]]) do
      begin
        inc(j);
        dec(m);
        inc(k);
      end;
      k:=k*2+1;
      if k>max then
      begin
        max:=k;
        b:=m+1;
        e:=j-1;
      end;
      push(i);
    end          else push(i);

  end;
  writedata;
end.
Re: Why I got WA#2? Program is here, I'm sure my alg is correct!!!
Posted by Виктор Крупко 8 Apr 2005 22:31
example:
Input:
1
output
_
Input:
22
output
_
Input
111232
output
232

It is necessary to remove the most left
It is 111