Sie sind auf Seite 1von 9

1)

uses crt;
type
tree=^node;
node=record
info:integer;
left:tree;
right:tree;
end;
var
root:tree;x,tong,chon,sonut:integer;ch:char;
procedure Init(var root:tree);
begin
new(root);
root:=nil;
end;
procedure dd(var root:tree;x:integer);
var p,!,l:tree;
begin
new(p);
p^"info:=x;
p^"left:=nil;
p^"right:=nil;
if(root=nil)then
root:=p
else
begin
new(!);new(l);
!:=root;
while(!#$nil)and(p^"info#$!^"info)do
begin
l:=!;
if(p^"info$!^"info)then
!:=!^"right
else !:=!^"left;
end;
if(!=nil)then
if(p^"info$l^"info)then l^"right:=p
else if(p^"info#l^"info)then l^"left:=p
else if(x=!^"info)then write(%da co%);
end;
end;
procedure &rint'()(root:tree);
begin
if(root#$nil)then
begin
print'()(root^"left);
write(root^"info:*);
print'()(root^"right);
end;
end;
function +u,(root:tree;var tong:integer):integer;
begin
if(root#$nil)then
begin
+u,:=+u,(root^"left,tong);
tong:=tong-1;
+u,:=+u,(root^"right,tong);
end;
+u,:=tong;
end;
function .ind(root:tree;x:integer):boolean;
var p:tree;
begin
new(p);
p:=root;
while(p#$nil)and(p^"info#$x)do
begin
if(x$p^"info)then
p:=p^"right
else p:=p^"left;
end;
if(p=nil)then .ind:=false
else .ind:=true;
end;
procedure /elete(var root:tree;x:integer);
var p,!,l,r,t:tree;
begin
new(p);new(!);
!:=nil;
p:=root;
while(p#$nil)and(p^"info#$x)do
begin
!:=p;
if(x$p^"info)then
p:=p^"right
else p:=p^"left;
end;
if(p^"info=x)then
begin
if(p^"right=nil)and(p^"left=nil)then
if(x$!^"info)then !^"right:=nil
else !^"left:=nil;
if(p^"right=nil)and(p^"left#$nil)then
if(p^"info$!^"info)then
!^"right:=p^"left
else !^"left:=p^"left;
if(p^"right#$nil)and(p^"left=nil)then
if(p^"info$!^"info)then
!^"right:=p^"right
else !^"left:=p^"right;
if(p^"right#$nil)and(p^"left#$nil)then
begin
new(r);r:=p^"right;
new(t);t:=p;
while(r^"left#$nil)do
begin
t:=r;r:=r^"left;
end;
if(t^"info$r^"info)then
t^"left:=r^"right
else
t^"right:=r^"right;
p^"info:=r^"info;
end;
end;

end;
0function +o1(ode(root:tree;var sonut:integer):integer;
begin
if(root#$nil)then
begin
+o1node:=+o1(ode(root^"left,sonut);
+o1node:=+o1node(root^"right,sonut);
if(root^"left=nil)and(root^"right=nil)then
inc(sonut);
end;
+o1node:=sonut;
end;2
procedure +o1(ode(root:tree;var sonut:integer);
begin
if(root#$nil)then
begin
+o1(ode(root^"left,sonut);
+o1node(root^"right,sonut);
if(root^"left=nil)and(root^"right=nil)then
inc(sonut);
end;
end;
begin
clrscr;

init(root);

repeat
writeln(% 34(5%);
writeln(% 116he, %);
writeln(% 716i, %);
writeln(% 819oa %);
writeln(% *16inh6ong%);
writeln(% :1In;ay %);
writeln(% <1+o1(ut1'a%);
writeln(% =14xit %);
>rite(%?an chon:%);readln(chon);
case(chon) of
1:begin
repeat
>rite(%(hap phan tu can the,(nhap @1 de dung):%);
readln(x);
if(x#$@1)then
add(root,x);
until x=@1;
end;
7:begin
>rite(%nhap phan tu can ti,:%);
readln(x);
if(.ind(root,x)=true)then
writeln(%ti, thay%)
else writeln(%Ahong ti, thay%);
end;
8:begin
write(%nhap gia tri can xoa:%);readln(x);
delete(root,x);
end;
*:begin
tong:=B;
writeln(%6ong cay nhi phan la:%,+u,(root,tong));
end;
::begin
print'()(root);
writeln;
end;
<:begin
sonut:=B;
so1node(root,sonut);
writeln(%so nut la:%,sonut);
end;
end
until chon==;
end"
7)
&rogra, Ciai6hua;
5ses crt;
Dar n: byte;
.unction Ciaithua(n:byte):longint;
?egin
If (n#=1) then
Ciaithua:=1
4lse
Ciaithua:= Ciaithua(n@1)En;
4nd;
?4CI(
;lrscr;
>rite(%(hap n: %); )eadln(n);
>rite(n,%F= %,Ciaithua(n));
)eadln;
4(/"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

&rogra, .ibonaci7;
5ses crt;
Dar n: byte;
.unction .ibonaci(n:byte):longint;
?egin
If (n#=1) then
.ibonaci:= 1
4lse
.ibonaci:= .ibonaci(n@1)-.ibonaci(n@7);
4nd;
?4CI(
;lrscr;
>rite(%(hap n: %); )eadln(n);
>rite(%+o .ibonaci thu %,n,% la: %,.ibonaci(n));
)eadln;
4(/"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

&rogra, 6hapG(8;
5ses crt;
Dar n:byte;
,?,;:char;
&rocedure 6hapG((n:byte;:char;?:char;;:char);
?egin
If n=1 then
>riteln(,% @$ %,?)
4lse
?egin
6hapG((n@1,,;,?);
6hapG((1,,?,;);
6hapG((n@1,;,?,);
4nd;
4nd;
?4CI(
;lrscr;
>rite(%(hap so dia: %); )eadln(n);
>rite(%(hap ten thap 1: %); )eadln();
>rite(%(hap ten thap 7: %); )eadln(?);
>rite(%(hap ten thap 8: %); )eadln(;);
writeln(%Huy trinh chuyen dia nhu sau:%);
6hapG((n,,?,;);
)eadln;
4(/"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

progra, 6ext.ile;
uses crt;
const filena,e=%;:IDa nban"txt%;
var f: text;
s: string;
chon: char;
de,: byte;
function de,tu(s: string):integer;
var i,d: integer;
begin
d:=1;
for i:=1 to length(s) do
if (sJiK=% %) and (sJi-1K #$ % %) then
d:=d-1;
de,tu:=d;
end;
begin
clrscr;
assign(f,filena,e);
0rewrite(f);
repeat
write(%(hap ,ot cau tho: %); readln(s);
writeln(f,s);
write(%(hap tiep hay ngungL 6M(%); readln(chon);
until upcase(chon)=%(%;2
reset(f); 0/e, so dong trong van ban tren2
0de,:=B;
while not eof(f) do
begin
readln(f,s);
de,:=de,-1;
end;
write(%+o dong cua van ban tren la: %,de,);
readln;2
de,:=B;
while not eof(f) do 0/e, so tu trong van ban tren2
begin
readln(f,s);
de,:=de,-de,tu(s);
end;
write(%+o tu trong van ban tren: %,de,);
readln;
close(f);

end"

8)
progra, ;huanGoa1;
uses crt;
var s:string;
f:text;
function ;huanGoa(var s: string):string;
const space=N87;
var i,A:byte;
begin
while sJ1K=space do
delete(s,1,1);
while sJlength(s)K=space do
delete(s,length(s),1);
repeat
A:=pos(space-space,s);
if A$B then
delete(s,A,1);
until A=B;
sJ1K:=upcase(sJ1K);
for i:=7 to length(s) do
if sJiK in J%%""%O%K then
sJiK:=chr(ord(sJiK)-87);
for i:=1 to length(s) do
if (sJiK=space) then
sJi-1K:=upcase(sJi-1K);
;huanGoa:=s;
end; ?4CI(
clrscr;
write(%(hap chuoi Go6en can chuan hoa: %);readln(s);
write(%;huoi sau Ahi chuan hoa: %,;huanGoa(s));
assign(f,%/:Ihoten"txt%);
rewrite(f);

writeln(f,s);
close(f);
readln;
4(/"

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


progra, Huan'y7;
uses crt;
const filena,e=%/:I/u'ieu"dat%;
type GangGoa= )ecord
3aGang:integer;
6enGang:string;
/onCia:integer;
+o'uong:integer;
6hanh6ien:real;
end;
/anh+ach=arrayJ1""1BBK of GangGoa;
.=.ile of GangGoa;
var :/anh+ach;
f: .;
procedure (hap/+(var :/anh+ach; var n:integer);
var chon:char;
begin
n:=B;
repeat
n:=n-1;
with JnK do
begin
writeln(%/anh sach cac ,at hangF%);
write(%3a hang: %);readln(3aGang);
write(%6en hang: %);readln(6enGang);
write(%/on gia: %);readln(/onCia);
write(%+o luong: %);readln(+o'uong);
6hanh6ien:=+o'uongE/onCia;

end;
write(%(hap tiep hay ngung 6I(%);readln(chon);
clrscr;
until upcase(chon)=%(%;
end;
procedure Chi/'(var f:.;:/anh+ach;n:integer);
var i:integer;
begin
rewrite(f);
for:=1 to n do
write(f,JiK);
end;
procedure /oc/'(var f:.;:/anh+ach);
var n,i:integer;
te,p:GangGoa;
begin
reset(f);
n:=B;
while not eof(f) n do
begin
n:=n-1;
read(f,JiK);
end;
close(f);
for i:=1 to (n@1) do
for P:=i-1 to n do
if JiK"3aGang$JPK"3aGang then
begin
te,p:=JiK;
JiK:=JPK;
JPK:=te,p;
end;
rewrite(f);
for i:=1 to n do
write(f,JiK);
close(f);
end;
procedure In/'(f:GangGoa);
var
begin
reset(f);
read(f,);
writeln(% /(G +;G ;; 36 G(C%);

writeln(%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%);
write(%- +66 - 3a hang - 6en hang - +o'g - /on gia - 6hanh tien
-%);
for i:=1 to filesiQe(f) do
begin
read(f,JiK);
with JiK do

write(%-%,i:8,%-%,3aGang::,%-%,6enGang:R,%-%,+o'uong::,%-%,/onCia:=,%-%
,6hanh6ien:S,%-%);
end;
end;
?4CI(
clrscr;
assign(f,filena,e);
(hap/s();
Chi/l(f,);
/oc/l(,f);
+ap9ep(f,);
In/'(f);
close(f);
readln;
4(/"

Das könnte Ihnen auch gefallen