ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1196. History Exam

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
Posted by ruanzihang 21 May 2009 20:52
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.
Re: program using recursion, Please help
Posted by benia 25 May 2009 21:37
Thanks
Re: program using recursion, Please help
Posted by SuperLight 26 May 2009 10:51