program using recursion, Please help
Posted by
benia 13 May 2009 13:14
Edited by author 29.05.2009 13:30
Re: program using recursion, Please help
type
arr=array[1..15000]of longint;
var
sum,i,j,n,m,x1:longint;
a:arr;
procedure search(var f:arr;x,p,q:longint;var sum:longint);
var
c:integer;
begin
c:=(p+q)div 2;
if p>q then exit;
if x=f[c] then inc(sum)
else if x>f[c] then search(f,x,c+1,q,sum)
else search(f,x,p,c-1,sum);
end;
begin
readln(n);sum:=0;
for i:=1 to n do
readln(a[i]);
readln(m);
for i:=1 to m do
begin
readln(x1);
search(a,x1,1,n,sum);
end;
write(sum);
end.