noi.openjudge.cn题解

program ch011101;
var
n,l,r,x,m,i,t,ans,k:longint;
b:boolean;
a:array[0..5000000] of longint;
begin
readln(n);
for i:=1 to n do read(a[i]);
readln(m);
for k:=1 to m do begin
readln(t);
l:=1;
r:=n;
b:=true;
while l<r do begin
x:=(l+r) div 2;
if a[x]=t then begin b:=false; writeln(t); break; end;
if t>a[x] then l:=x+1;
if t<a[x] then r:=x;
end;
if b then begin
ans:=maxlongint;
for i:=-1 to 1 do if (r+i>0) and (r+i<=n) then if abs(a[r+i]-t)<abs(ans-t) then ans:=a[r+i];
writeln(ans);
end;
end;
end.

program ch02066252;
var
s1,s2:string;
i,j,k:longint;
f:array[0..50,-1..50] of boolean;
begin
readln(s1);
readln(s2);
f[0,0]:=true;
for i:=1 to length(s1) do
for j:=0 to length(s2) do
if s1[i]='*' then begin if f[i-1,j] or f[i,j-1] then f[i,j]:=true; end
else if s1[i]='?' then begin if f[i-1,j-1] then f[i,j]:=true; end
else if f[i-1,j-1] and (s1[i]=s2[j]) then f[i,j]:=true;
if f[length(s1),length(s2)] then writeln('matched') else writeln('not matched');
end.

program ch04061455;
var
n,l,i,c:longint;
begin
while true do begin
l:=0;c:=0;
readln(n);
if n=0 then break;
while n and 1=0 do begin inc(l); n:=n>>1; end;
while n and 1=1 do begin inc(c); inc(l); n:=n>>1; end;
n:=n or 1;
for i:=1 to l-c+1 do n:=n<<1;
for i:=1 to c-1 do begin n:=n<<1; n:=n or 1; end;
writeln(n);
end;
end.