ac1239.pas
来自「同济大学 Online在线题库 AC源代码合集 程序设计竞赛必看资料」· PAS 代码 · 共 44 行
PAS
44 行
program tju1239;
var
p,q:ansistring;
n,u,lp,lq,l,i,pp,pq,count:word;
function match(sp,sq,l:word):boolean;
var
i:word;
begin
for i:=1 to l do
if (p[sp+i]<>'?') and (q[sq+i]<>'?') and (p[sp+i]<>q[sq+i]) then begin
match:=false;exit;
end;
match:=true;
end;
begin
repeat
readln(p);lp:=length(p);
readln(n);count:=0;
if pos('*',p)=0 then
for u:=1 to n do begin
readln(q);lq:=length(q);
if (lp=lq) and match(0,0,lp) then inc(count);
end
else
for u:=1 to n do begin
readln(q);lq:=length(q);
pp:=pos('*',p);
if (lq<pp-1) or not match(0,0,pp-1) then continue;
pq:=pp-1;
for i:=pp+1 to lp do
if p[i]='*' then begin
l:=i-pp-1;
while pq+l<=lq do
if match(pp,pq,l) then break else inc(pq);
if pq+l>lq then break;
pp:=i;inc(pq,l);
end;
l:=lp-pp;
if (pq+l<=lq) and match(pp,lq-l,l) then inc(count);
end;
writeln(n-count);
until seekeof;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?