SlideShare a Scribd company logo
1 of 4
Download to read offline
BỘ GIÁO DỤC VÀ ĐÀO TẠO
ĐẠI HỌC HUẾ
KỲ THI TUYỂN SINH SAU ĐẠI HỌC NĂM 2005
Đáp án đề thi tuyển sinh Cao học
Môn thi: Ngôn ngữ lập trình
Câu 1: 1,5 đ
Kết quả in ra trên màn hình:
8 4 10 5 9
8 4 5 10 9
8 4 5 9 10
4 8 5 9 10
4 5 8 9 10
* Dòng 1: 0,5 đ
* Dòng 2-3: 0,5 đ
* Dòng 4-5: 0,5 đ
Câu 2: 4,0 đ
a) 1,0 đ
Function Addr(FirstS: TroMH; BMaMH: Integer):TroMH;
Begin
If FirstS=nil then Addr:=nil
else if FirstS^.MaMH=BMaMH then Addr:=FirstS
else Addr:=Addr(FirstS^.next, BMaMH);
End;
* Xử lý trường hợp để có Addr=nil: 0,5 đ
* Xử lý trường hợp để có Addr<>nil: 0,5 đ
b) 3,0 đ
Procedure ListOfSubjects(FirstT: TroGV; BMaGV: St8); (1,5 đ)
Procedure LOS(F: TroM);
var stt: integer; p: TroMH;
Begin If F<>nil then
begin stt:=1; writeln(‘STT’:5, ‘Ten mon hoc’:30, ‘So DVHT’:10);
while F<>nil do
begin p:=Addr(FirstS, F^.MaM);
writeln(stt:5, p^.TenMH:30, p^.SoDVHT:10);
F:=F^.Tiep; stt:=stt+1;
end;
end;
End;
Nguyễn Lý Hữu Huấn
Begin If (FirstT<>nil)and(FirstT^.MaGV<=BMaGV) then
If FirstT^.MaGV=BMaGV then LOS(FirstT^.DSM)
else ListOfSubjects(FirstT^.Down, BMaGV);
End;
* Định vị đến nút giáo viên cần tìm (có sử dụng danh sách tăng dần): 0,5 đ
* Duyệt danh sách mã môn học: 0,5 đ
* In theo mẫu: 0,5 đ
Procedure ListOfTeachers(FirstT: TroGV; BMaM: Integer); (1,5 đ)
var stt: integer;
Procedure LOT(F: TroGV; BMaM: Integer);
Procedure Find_and_Print(P: TroM; BMaM: Integer);
Begin If P<>nil then
if P^.MaM=BMaM then
begin writeln(stt:5, F^.HoTenGV:30); stt:= stt+1;
end
else Find_and_Print(P^.Tiep, BMaM);
End;
Begin If F<>nil then
begin Find_and_Print(F^.DSM, BMaM);
LOT(F^.down, BMaM);
end;
End;
Begin If FirstT<>nil then
begin stt:=1; writeln(‘STT’:5, ‘Ho ten giao vien’:30);
LOT(FirstT, BMaM);
end;
End;
* Duyệt mọi nút giáo viên: 0,5 đ
* In theo mẫu: 1,0 đ
Câu 3: 4,5 đ
a) 1,5 đ
Function Muc(Top, p: TroNutTrenCay):Word ;
Function Cha(Top, p: TroNutTrenCay):TroNutTrenCay;
Begin If (Top=nil)or(Top=p) then Cha:=nil
else If (Top^.Left=p) or (Top^.Right=p) then Cha:=Top
else if Cha(Top^.Left, p)<>nil then Cha:=Cha(Top^.Left, p)
else Cha:= Cha(Top^.Right, p);
End;
Nguyễn Lý Hữu Huấn
Begin If Top=nil then Muc:=0
else If p=Top then Muc:=1
else Muc:=Muc(Top, Cha(Top, p))+1;
End;
* Xác định địa chỉ nút cha của p: + 0,5 đ (trường hợp cha=nil)
+ 0,5 đ (trường hợp cha<>nil)
* Từ đó xác định mức của nút p: 0,5 đ
b) 2,0 đ
Procedure InsertQueue(var First, Last: TroNutTrenDS; X: TroNutTrenCay); (1,0 đ)
var p: TroNutTrenDS;
Begin new(p); p^.Info:=X; p^.next:=nil;
If First=nil then begin First:=p; Last:=p; end
Else begin Last^.next:=p; Last:=p; end;
End;
* Xử lý trường hợp First = nil: 0,5 đ
* Xử lý trường hợp First <> nil: 0,5 đ
Procedure DeleteQueue(var First, Last: TroNutTrenDS; var X: TroNutTrenCay); (1,0 đ)
var p: TroNutTrenDS;
Begin
If First=nil then write(‘Khong xoa duoc’)
Else If First=Last then
begin X:=First^.Info;dispose(First); First:=nil; Last:=nil; end
Else
begin p:=First; X:=p^.Info; First:=p^.next; dispose(p); end;
End;
* Xử lý trường hợp First = nil và First=Last: 0,5 đ
* Xử lý trường hợp còn lại: 0,5 đ
c) 1,0 đ (không chia nhỏ)
Procedure Lietke(Top: TroNutTrenCay);
var First, Last: TroNutTrenDS; X: TroNutTrenCay;
Begin If Top<>nil then
begin First:=nil; Last:=nil;
InsertQueue(First, Last, Top); writeln(Top^.Value);
Repeat
DeleteQueue(First, Last, X);
If X^.Left<>nil then begin InsertQueue(First, Last, X^.Left);
writeln(X^.Left^.Value);
end;
Nguyễn Lý Hữu Huấn
If X^.Right<>nil then begin InsertQueue(First, Last, X^.Right);
writeln(X^.Right^.Value);
end;
Until First=nil;
end;
End;
Nguyễn Lý Hữu Huấn

More Related Content

Viewers also liked

Ctdl 2005 chuong 2
Ctdl 2005 chuong 2Ctdl 2005 chuong 2
Ctdl 2005 chuong 2Hồ Lợi
 
Funciones de la admon y tipos de gerentes
Funciones de la admon y tipos de gerentesFunciones de la admon y tipos de gerentes
Funciones de la admon y tipos de gerentesalexaroldo
 
Edad moderna
Edad modernaEdad moderna
Edad modernalygobu78
 
Actividad trabajo colaborativo ♥
Actividad trabajo colaborativo ♥Actividad trabajo colaborativo ♥
Actividad trabajo colaborativo ♥alejacelis
 
Woocommerce google ecommerce tracking
Woocommerce  google ecommerce trackingWoocommerce  google ecommerce tracking
Woocommerce google ecommerce trackingEtietop Demas
 
Krista schoellhorn digital portfolio
Krista schoellhorn   digital portfolioKrista schoellhorn   digital portfolio
Krista schoellhorn digital portfolioSchoellhorn Krista
 
Angulos mediante el uso de escuadras
Angulos mediante el uso de escuadrasAngulos mediante el uso de escuadras
Angulos mediante el uso de escuadrasTonatiuh Herrera
 

Viewers also liked (12)

Ctdl 2005 chuong 2
Ctdl 2005 chuong 2Ctdl 2005 chuong 2
Ctdl 2005 chuong 2
 
Ctdl 2006
Ctdl   2006Ctdl   2006
Ctdl 2006
 
Ctdl 2007-1
Ctdl   2007-1Ctdl   2007-1
Ctdl 2007-1
 
Funciones de la admon y tipos de gerentes
Funciones de la admon y tipos de gerentesFunciones de la admon y tipos de gerentes
Funciones de la admon y tipos de gerentes
 
Edad moderna
Edad modernaEdad moderna
Edad moderna
 
Diap. infor.
Diap. infor.Diap. infor.
Diap. infor.
 
Actividad trabajo colaborativo ♥
Actividad trabajo colaborativo ♥Actividad trabajo colaborativo ♥
Actividad trabajo colaborativo ♥
 
Ctdl 2005
Ctdl   2005Ctdl   2005
Ctdl 2005
 
Woocommerce google ecommerce tracking
Woocommerce  google ecommerce trackingWoocommerce  google ecommerce tracking
Woocommerce google ecommerce tracking
 
Krista schoellhorn digital portfolio
Krista schoellhorn   digital portfolioKrista schoellhorn   digital portfolio
Krista schoellhorn digital portfolio
 
Jenga
JengaJenga
Jenga
 
Angulos mediante el uso de escuadras
Angulos mediante el uso de escuadrasAngulos mediante el uso de escuadras
Angulos mediante el uso de escuadras
 

More from Hồ Lợi

Tóm tắt các hàm chuẩn của c
Tóm tắt các hàm chuẩn của cTóm tắt các hàm chuẩn của c
Tóm tắt các hàm chuẩn của cHồ Lợi
 
Lect04 functions
Lect04 functionsLect04 functions
Lect04 functionsHồ Lợi
 
Ky thuatkhudequy
Ky thuatkhudequyKy thuatkhudequy
Ky thuatkhudequyHồ Lợi
 
Itt epc assignment
Itt epc assignmentItt epc assignment
Itt epc assignmentHồ Lợi
 
Huong danontapc
Huong danontapcHuong danontapc
Huong danontapcHồ Lợi
 
H hai epc_baitap
H hai epc_baitapH hai epc_baitap
H hai epc_baitapHồ Lợi
 
Giaotrinhbaitapkythuatlaptrinh
GiaotrinhbaitapkythuatlaptrinhGiaotrinhbaitapkythuatlaptrinh
GiaotrinhbaitapkythuatlaptrinhHồ Lợi
 
Giao trinh ky thuat lap trinh 2
Giao trinh ky thuat lap trinh 2Giao trinh ky thuat lap trinh 2
Giao trinh ky thuat lap trinh 2Hồ Lợi
 
Giao trinh c c++
Giao trinh c c++Giao trinh c c++
Giao trinh c c++Hồ Lợi
 
Epc assignment
Epc assignmentEpc assignment
Epc assignmentHồ Lợi
 
Epc test practical
Epc test practicalEpc test practical
Epc test practicalHồ Lợi
 
De thic++ --th
De thic++ --thDe thic++ --th
De thic++ --thHồ Lợi
 

More from Hồ Lợi (20)

Xu ly chuoi
Xu ly chuoiXu ly chuoi
Xu ly chuoi
 
Tóm tắt các hàm chuẩn của c
Tóm tắt các hàm chuẩn của cTóm tắt các hàm chuẩn của c
Tóm tắt các hàm chuẩn của c
 
T4
T4T4
T4
 
Nguyen lyoop
Nguyen lyoopNguyen lyoop
Nguyen lyoop
 
Lect04 functions
Lect04 functionsLect04 functions
Lect04 functions
 
Ky thuatkhudequy
Ky thuatkhudequyKy thuatkhudequy
Ky thuatkhudequy
 
Itt epc assignment
Itt epc assignmentItt epc assignment
Itt epc assignment
 
Huong danontapc
Huong danontapcHuong danontapc
Huong danontapc
 
H hai epc_baitap
H hai epc_baitapH hai epc_baitap
H hai epc_baitap
 
Gtrinh oop
Gtrinh oopGtrinh oop
Gtrinh oop
 
Giaotrinhbaitapkythuatlaptrinh
GiaotrinhbaitapkythuatlaptrinhGiaotrinhbaitapkythuatlaptrinh
Giaotrinhbaitapkythuatlaptrinh
 
Giao trinh ky thuat lap trinh 2
Giao trinh ky thuat lap trinh 2Giao trinh ky thuat lap trinh 2
Giao trinh ky thuat lap trinh 2
 
Giao trinh c c++
Giao trinh c c++Giao trinh c c++
Giao trinh c c++
 
File trong c_
File trong c_File trong c_
File trong c_
 
Epc assignment
Epc assignmentEpc assignment
Epc assignment
 
Epc test practical
Epc test practicalEpc test practical
Epc test practical
 
De thic++ --th
De thic++ --thDe thic++ --th
De thic++ --th
 
Dethi c++ -lt
Dethi c++ -ltDethi c++ -lt
Dethi c++ -lt
 
Debug trong c
Debug trong cDebug trong c
Debug trong c
 
D05 stl
D05 stlD05 stl
D05 stl
 

Ctdl 2005 - dap an

  • 1. BỘ GIÁO DỤC VÀ ĐÀO TẠO ĐẠI HỌC HUẾ KỲ THI TUYỂN SINH SAU ĐẠI HỌC NĂM 2005 Đáp án đề thi tuyển sinh Cao học Môn thi: Ngôn ngữ lập trình Câu 1: 1,5 đ Kết quả in ra trên màn hình: 8 4 10 5 9 8 4 5 10 9 8 4 5 9 10 4 8 5 9 10 4 5 8 9 10 * Dòng 1: 0,5 đ * Dòng 2-3: 0,5 đ * Dòng 4-5: 0,5 đ Câu 2: 4,0 đ a) 1,0 đ Function Addr(FirstS: TroMH; BMaMH: Integer):TroMH; Begin If FirstS=nil then Addr:=nil else if FirstS^.MaMH=BMaMH then Addr:=FirstS else Addr:=Addr(FirstS^.next, BMaMH); End; * Xử lý trường hợp để có Addr=nil: 0,5 đ * Xử lý trường hợp để có Addr<>nil: 0,5 đ b) 3,0 đ Procedure ListOfSubjects(FirstT: TroGV; BMaGV: St8); (1,5 đ) Procedure LOS(F: TroM); var stt: integer; p: TroMH; Begin If F<>nil then begin stt:=1; writeln(‘STT’:5, ‘Ten mon hoc’:30, ‘So DVHT’:10); while F<>nil do begin p:=Addr(FirstS, F^.MaM); writeln(stt:5, p^.TenMH:30, p^.SoDVHT:10); F:=F^.Tiep; stt:=stt+1; end; end; End; Nguyễn Lý Hữu Huấn
  • 2. Begin If (FirstT<>nil)and(FirstT^.MaGV<=BMaGV) then If FirstT^.MaGV=BMaGV then LOS(FirstT^.DSM) else ListOfSubjects(FirstT^.Down, BMaGV); End; * Định vị đến nút giáo viên cần tìm (có sử dụng danh sách tăng dần): 0,5 đ * Duyệt danh sách mã môn học: 0,5 đ * In theo mẫu: 0,5 đ Procedure ListOfTeachers(FirstT: TroGV; BMaM: Integer); (1,5 đ) var stt: integer; Procedure LOT(F: TroGV; BMaM: Integer); Procedure Find_and_Print(P: TroM; BMaM: Integer); Begin If P<>nil then if P^.MaM=BMaM then begin writeln(stt:5, F^.HoTenGV:30); stt:= stt+1; end else Find_and_Print(P^.Tiep, BMaM); End; Begin If F<>nil then begin Find_and_Print(F^.DSM, BMaM); LOT(F^.down, BMaM); end; End; Begin If FirstT<>nil then begin stt:=1; writeln(‘STT’:5, ‘Ho ten giao vien’:30); LOT(FirstT, BMaM); end; End; * Duyệt mọi nút giáo viên: 0,5 đ * In theo mẫu: 1,0 đ Câu 3: 4,5 đ a) 1,5 đ Function Muc(Top, p: TroNutTrenCay):Word ; Function Cha(Top, p: TroNutTrenCay):TroNutTrenCay; Begin If (Top=nil)or(Top=p) then Cha:=nil else If (Top^.Left=p) or (Top^.Right=p) then Cha:=Top else if Cha(Top^.Left, p)<>nil then Cha:=Cha(Top^.Left, p) else Cha:= Cha(Top^.Right, p); End; Nguyễn Lý Hữu Huấn
  • 3. Begin If Top=nil then Muc:=0 else If p=Top then Muc:=1 else Muc:=Muc(Top, Cha(Top, p))+1; End; * Xác định địa chỉ nút cha của p: + 0,5 đ (trường hợp cha=nil) + 0,5 đ (trường hợp cha<>nil) * Từ đó xác định mức của nút p: 0,5 đ b) 2,0 đ Procedure InsertQueue(var First, Last: TroNutTrenDS; X: TroNutTrenCay); (1,0 đ) var p: TroNutTrenDS; Begin new(p); p^.Info:=X; p^.next:=nil; If First=nil then begin First:=p; Last:=p; end Else begin Last^.next:=p; Last:=p; end; End; * Xử lý trường hợp First = nil: 0,5 đ * Xử lý trường hợp First <> nil: 0,5 đ Procedure DeleteQueue(var First, Last: TroNutTrenDS; var X: TroNutTrenCay); (1,0 đ) var p: TroNutTrenDS; Begin If First=nil then write(‘Khong xoa duoc’) Else If First=Last then begin X:=First^.Info;dispose(First); First:=nil; Last:=nil; end Else begin p:=First; X:=p^.Info; First:=p^.next; dispose(p); end; End; * Xử lý trường hợp First = nil và First=Last: 0,5 đ * Xử lý trường hợp còn lại: 0,5 đ c) 1,0 đ (không chia nhỏ) Procedure Lietke(Top: TroNutTrenCay); var First, Last: TroNutTrenDS; X: TroNutTrenCay; Begin If Top<>nil then begin First:=nil; Last:=nil; InsertQueue(First, Last, Top); writeln(Top^.Value); Repeat DeleteQueue(First, Last, X); If X^.Left<>nil then begin InsertQueue(First, Last, X^.Left); writeln(X^.Left^.Value); end; Nguyễn Lý Hữu Huấn
  • 4. If X^.Right<>nil then begin InsertQueue(First, Last, X^.Right); writeln(X^.Right^.Value); end; Until First=nil; end; End; Nguyễn Lý Hữu Huấn