PBCWRI - Writing

Tác giả: flashmt

Ngôn ngữ: Pascal

const fi='';
      fo='';
      maxn=3000000;
var a:array[1..maxn] of char;
    b,c:array[65..122] of longint;
    i,re,la,lb:longint;
    ch:char;
    last:boolean;

function check:boolean;
var i:longint; kt:boolean;
begin
     kt:=true;  check:=true;
     for i:=65 to 90 do
         if b[i]<>c[i] then
         begin
              kt:=false;
              check:=false;
              break;
         end;
     if kt then
        for i:=97 to 122 do
            if b[i]<>c[i] then
            begin
                 check:=false;
                 break;
            end;
end;

begin
     assign(input,fi);
     reset(input);
     readln(la,lb);
     fillchar(b,sizeof(b),0);
     for i:=1 to la do
     begin
          read(ch);
          inc(b[ord(ch)]);
     end;
     readln;
     fillchar(c,sizeof(c),0);
     for i:=1 to la do
     begin
          read(a[i]);
          inc(c[ord(a[i])]);
     end;
     last:=check;
     if last then re:=1 else re:=0;
     for i:=la+1 to lb do
     begin
          read(a[i]);
          if a[i]=a[i-la] then
          begin
               if last then inc(re);
          end
          else
          begin
               inc(c[ord(a[i])]);
               dec(c[ord(a[i-la])]);
               last:=check;
               if last then inc(re);
          end;
     end;
     close(input);
     assign(output,fo);
     rewrite(output);
     write(re);
     close(output);
end.

Download