比赛 20120706 评测结果 AATTTTTTTT
题目名称 解密 最终得分 20
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-07-06 09:21:05
显示代码纯文本
var
  yes:boolean;
  i,l1,l2,now,j,k:longint;
  ch:char;
  s1,s2:array[0..1000000]of ansistring;
  a,b:array[0..1000000]of longint;

begin
  assign(input,'kriptogram.in'); reset(input);
  assign(output,'kriptogram.out'); rewrite(output);
  l1:=0;
  repeat
    inc(l1);
    read(ch);
    if ch='$' then break;
    repeat
      s1[l1]:=s1[l1]+ch;
      read(ch);
    until ch=' ';
  until false;
  readln;
  l2:=0;
  repeat
    inc(l2);
    read(ch);
    if ch='$' then break;
    repeat
      s2[l2]:=s2[l2]+ch;
      read(ch);
    until ch=' ';
  until false;

  dec(l1);
  dec(l2);

  now:=0;
  for i:=1 to l2 do
  begin
    for j:=1 to i-1 do
    if s2[i]=s2[j] then
    begin
      b[i]:=b[j];
      break;
    end;
    if b[i]=0 then
    begin
      inc(now);
      b[i]:=now;
    end;
  end;

  for k:=1 to l1-l2+1 do
  begin
    now:=0;
    yes:=true;
    for i:=k to k+l2-1 do
    begin
      a[i-k+1]:=0;
      for j:=k to i-1 do
      if s1[i]=s1[j] then
      begin
        a[i-k+1]:=a[j-k+1];
        break;
      end;
      if a[i-k+1]=0 then
      begin
        inc(now);
        a[i-k+1]:=now;
      end;
      if a[i-k+1]<>b[i-k+1] then
      begin
        yes:=false;
        break;
      end;
    end;
    if yes then
    begin
      writeln(k);
      break;
    end;
  end;
  close(input);
  close(output);
end.