{Ch¬ng tr×nh theo ph¬ng ph¸p d©y truyÒn t¬ng tù nh bµi tËp 2 vµ bµi tËp 3} Bµi 5 program danhsachlienket; type banghi=record id:string; password:string; end; elementtype=banghi; point=^usernode; usernode=record data:elementtype; next:point; end; bangbam=array[0 12] of point; var f:text; userRec:banghi; userT:bangbam; found:boolean; loc:integer; p:point; ten:string; c:char; dem:integer; procedure khoitao(var T:bangbam); var i:integer; begin for i:=0 to 12 do T[i]:=nil; end; function hambam(ten:string):integer; var tong:integer; i:integer; begin tong:=0; for i:=1 to length(ten) do tong:=tong+ord(ten[i]); hambam:=tong mod 11; end; procedure timkiem(T:bangbam;item:elementtype); begin loc:=hambam(item.password); p:=T[loc]; found:=false; dem:=1; while not found and (p<>nil) do if p^.data.password=item.password then begin found:=true; writeln('Password dung'); writeln('ID la ',p^.data.id); dem:=dem+1; end else begin dem:=dem+1; p:=p^.next; end; end; procedure nhap(var T:bangbam;item:elementtype); begin timkiem(T,item); if found=true then writeln('Item da co trong bang bam tai bang thu ',loc,'-',dem) else begin new(p); p^.data:=item; p^.next:=T[loc]; T[loc]:=p; writeln('da dien vao vi tri ',loc,' o bang thu ',dem); end; end; procedure luu; var i:integer; begin for i:=1 to 11 do begin p:=userT[i]; while p<>nil do begin write(f,'',p^.data.password,'*'); p:=p^.next; end; writeln(f,''); end; close(f); end; procedure doc; var i,j:integer; ten:string; begin readln(f,userrec.id); readln(f,userrec.password); end; begin khoitao(userT); assign(f,'bai5.txt'); filemode:=2; reset(f); while not eof(f) do begin doc; nhap(userT,userrec); end; close(f); begin writeln('Nhap password: ');readln(userrec.password); timkiem(userT,userrec); if found=false then writeln('Password sai'); end; readln; end. Bµi 6 program danhsachlienket; type banghi=record id:integer; end; elementtype=banghi; point=^usernode; usernode=record data:elementtype; next:point; end; bangbam=array[0 12] of point; var f:text; userRec:banghi; userT:bangbam; found:boolean; loc:integer; p:point; c:char; ten:string; vc:integer; dem:integer; Tsize:integer; co:array[0 12] of integer; procedure khoitao(var T:bangbam); var i:integer; begin for i:=0 to 12 do T[i]:=nil; co[i]:=0; end; function hambam(ten:integer):integer; begin hambam:=ten mod Tsize; end; procedure timkiem(T:bangbam;item:elementtype); begin loc:=hambam(item.id); p:=T[loc]; found:=false; dem:=1; while not found and (p<>nil) do if p^.data.id=item.id then begin found:=true; dem:=dem+1; end else begin dem:=dem+1; p:=p^.next; end; end; procedure nhap(var T:bangbam;item:elementtype); begin timkiem(T,item); if found=true then writeln('Gia tri da co trong bang bam tai bang thu ',loc,'-',dem) else begin if co[loc]=1 then vc:=vc+1; new(p); p^.data:=item; p^.next:=T[loc]; T[loc]:=p; co[loc]:=1; writeln('da dien vao vi tri ',loc,'-',dem); end; end; procedure ghi; var i:integer; begin for i:=1 to 11 do begin p:=userT[i]; while p<>nil do begin write('',p^.data.id,' '); p:=p^.next; end; writeln; end; end; begin khoitao(userT); vc:=1; writeln('Nhap Tsize: ');readln(Tsize); {writeln('Nhap gia tri cua so');readln(userrec.id);} for userrec.id:=1 to 100 do begin nhap(userT,userrec); end; writeln('so lan va cham la ',vc); writeln('Cac gia tri trong bang bam la:'); writeln; ghi; readln; end.