Tài liệu GIAI DE THI - Pdf 82

GIẢI ĐỀ THI CÁC NĂM
Laptrinh_Hieu
24
Bài giải chỉ mang tính chất tham khảo.
Không phải là đáp án của trường.
ĐỀ THI NĂM 2004
1. Câu 1
function ti(n:word):word;
begin
if n<10 then
ti := n
else
ti := (n mod 10) + ti(n div 10);
end;
2. Câu 2
Câu b,c xem bài 14 và đáp án phần Danh
sách móc nối.
{Câu a}
procedure load_file;
var f: text;
so:word;
r: tro;
begin
assign(f,'solieu.dat');
{$I-}
reset(f);
close(f);
{$I+}
if IOResult <> 0 then
begin
writeln('khong tim thay');

tim := t^.ten
else
if (T^.soao < n) then
tim := tim(T^.r, n)
else
tim := tim(T^.l, n);
end;
{Câu a}
function dem(t:tro):word;
begin
if t = nil then
dem := 0
else
dem := 1+ dem(t^.l)+ dem (t^.r);
end;
{Câu a}
procedure bosung(var t: tro; n: word;
tenct: string);
begin
if t = nil then
begin
new(t);
t^.soao := n;
t^.ten := tenct;
t^.l := nil;
t^.r := nil;
end
else
if n = t^.soao then
writeln(n, ' da co')

for i:= top downto 1 do
write(a[i]);
writeln;
end;
procedure np_ds(n: word);
var l,p:tro;
begin
l:= nil;
while n>0 do
begin
new(p);
p^.gtri := n mod 2;
p^.tiep := l;
l := p;
n := n div 2;
end;
p:=l;
while p<>nil do
begin
write(p^.gtri);
p := p^.tiep;
end;
writeln;
end;
procedure np(n: word);
begin
if n=1 then
write(1)
else
begin

end;
end;
{Tìm đỉnh đầu tiên của miền thứ m}
function tim_dinh(m: word): word;
var i: word;
begin
for i:=1 to n do
if mien[i] = m then
begin
tim_dinh := i;
exit;
end;
tim_dinh := 0;
end;
procedure bosung;
var i,j,dem: word;
begin
{xac dinh mien lien thong}
fillchar(mien,100,0);
dem := 0;
for i:=1 to n do
if mien[i] = 0 then
begin
dem := dem+1;
try(i,dem);
end;
GIẢI ĐỀ THI CÁC NĂM
Laptrinh_Hieu
26
if dem >1 then

while p<> nil do
begin
write('ten sach: ',p^.tens);
writeln('nxb: ',p^.namxb);
p := p^.tiep;
end;
end;
procedure liet_ke(t: trotg; ma:
word);
begin
if t = nil then
writeln('Khong tim thay');
else
if t^.matg = ma then
begin
oten := t^.tentg;
osach := t^.sachtg;
xuat;
end
else
if ma > t^.matg then
liet_ke(t^.phai, ma)
else
liet_ke(t^.trai, ma);
end;
procedure loai_bo(var t: trotg);
var r,p: trotg;
begin
if t <> nil then
begin

{Tạo mới 1 tác giả}
new(s);
s^.tens := ten;
s^.namxb := nam;
s^.tiep := nil;
new(t);
t^.matg := ma;
t^.tentg := tg;
t^.sachtg := s;
t^.trai := nil;
t^.phai := nil;
end
else
begin
{Tìm nút P mà P^.Trai = NIL hoặc
P^.Phai = NIL}
p := t; ok := true;
while (p^.matg <> ma) and ok do
begin
if ma > p^.matg then
GIẢI ĐỀ THI CÁC NĂM
Laptrinh_Hieu
27
if p^.phai <> nil then
p := p^.phai
else
ok := false
else
if p^.trai <> nil then
p := p^.trai

r^.tentg := tg;
r^.sachtg := s;
{Lựa chọn đưa vào trái hay phải}
if ma > p^.matg then
p^.phai := r
else
p^.trai := r;
end;
end;
end;
ĐỀ 2005
CÂU 3A
procedure timten(trokhach: khach; n:
word);
var t:khach;
begin
if trokhach = nil then
writeln('khong tim thay')
else
if trokhach^.sdt = n then
begin
write(trokhach^.ten);
write(trokhach^.sonha);
writeln(trokhach^.duong);
end
else
if n > trokhach^.sdt then
timten(trokhach^.phai,n)
else
timten(trokhach^.trai,n);


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status