比赛 20100927 评测结果 AAAAAAAAAAAAAAAA
题目名称 翻译玛雅著作 最终得分 100
用户昵称 kaaala 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-09-27 20:28:20
显示代码纯文本
program ex(input,output);
var len1,len2:longint;
    s1,s2:ansistring;
    suma,nowa:array['a'..'z'] of longint;
    sumb,nowb:array['A'..'Z'] of longint;
procedure main;
var i,flag,ans:longint;
begin
 fillchar(suma,sizeof(suma),0);
 fillchar(sumb,sizeof(sumb),0);
 fillchar(nowa,sizeof(nowa),0);
 fillchar(nowb,sizeof(nowb),0);
 
 for i:=1 to len1 do
 if s1[i] in ['a'..'z'] then inc(suma[s1[i]])
                        else inc(sumb[s1[i]]);

 flag:=0; ans:=0;
 
 for i:=1 to len2 do
 begin
  if s2[i] in ['a'..'z'] then begin
                               inc(nowa[s2[i]]);
                               if nowa[s2[i]]>suma[s2[i]] then inc(flag);
                              end
                         else begin
                               inc(nowb[s2[i]]);
                               if nowb[s2[i]]>sumb[s2[i]] then inc(flag);
                              end;
  if i>=len1 then
  begin
   if flag=0 then inc(ans);
   if s2[i-len1+1] in ['a'..'z'] then begin
                                       if nowa[s2[i-len1+1]]>suma[s2[i-len1+1]] then dec(flag);
                                       dec(nowa[s2[i-len1+1]]);
                                      end
                                 else begin
                                       if nowb[s2[i-len1+1]]>sumb[s2[i-len1+1]] then dec(flag);
                                       dec(nowb[s2[i-len1+1]]);
                                      end;
  end;
 end;
 
 writeln(ans);
end;
begin
 assign(input,'writing.in'); reset(input);
 assign(output,'writing.out'); rewrite(output);
 readln(len1,len2);
 readln(s1);
 readln(s2);
 main;
 close(input); close(output);
end.