比赛 noip_6 评测结果 WWWWWWWWWW
题目名称 回文词 最终得分 0
用户昵称 maxiem 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-10-08 21:28:34
显示代码纯文本
program palin;
var
  j,i,min,n:integer;
  s:array [-5000..5000] of char;
  c:array [1..5000] of integer;
begin
  for i:=-5000 to 5000 do s[i]:=' ';
  for i:=1 to 5000 do c[i]:=maxint;
  assign (input,'palin.in');
  reset (input);
  readln (n);
  for i:=1 to n do read (s[i]);
  close (input);
  assign (output,'palin.out');
  rewrite (output);
  if n div 2=0 then begin
    for i:=1 to n do for j:=i+1 to n do if s[j]<>s[i*2+1-j] then begin
      if abs(n-3*i)>0 then break;
      if c[i]=maxint then c[i]:=0;
      inc(c[i],2);
    end;
  end
  else begin
    for i:=1 to n do for j:=i to n do if s[j]<>s[i*2-j] then begin
      if abs(n-2*i+1)>0 then break;
      if c[i]=maxint then c[i]:=0;
      inc(c[i],2);
    end;
  end;
  min:=maxint;
  for i:=1 to n do if c[i]<min then min:=c[i];
  writeln (min);
  close (output);
end.