Vous êtes sur la page 1sur 12

Program Vi_Tri_Chuoi; Var St1,St2:String; Begin Writeln('VI TRI CHUOI CON TRONG CHUOI ME'); Writeln(' Ham Pos');

Writeln(' --------------'); Write('-Chuoi me: '); Readln(St1); Write('-Chuoi con: '); Readln(St2); Writeln('+Chuoi con bat dau tu vi tri thu: ',Pos(St2,St1), ' trong chuoi me'); Writeln; Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Program Chuoi_Doi_Xung; Var St:String; i,l:Byte; Begin Writeln('CHUOI DOI XUNG'); Writeln(' --------'); Write('-Nhap chuoi: '); Readln(St); l:=Length(St); i:=1; While (i < l Div 2) And (St[i] = St[l-i+1]) Do Begin i:=i+1; If i < (l Div 2) Then Writeln('+Chuoi nay doi xung') End; While (i < l Div 2) And (St[i] <> St[l-i+1]) Do Begin i:=i+1; If i < (l Div 2) Then Writeln('+Chuoi nay khong doi xung') End; Writeln; Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Program Dem_chuoi; Var St:String; dem:ARRAY['A'.. 'Z'] Of Integer; i:Integer; Ch:Char;

Begin Writeln('DEM SO LAN XUAT HIEN CUA KY TU TRONG CHUOI'); Writeln(' -----------'); Write('-Nhap chuoi: '); Readln(St); For i:=1 To Length(St) Do Dem[UpCase(St[i])]:= Dem[UpCase(St[i])]+1; Writeln; Writeln('+Cac ky tu trong chuoi la: '); For Ch:='A' To 'Z' Do If Dem[ch] > 0 Then Writeln('+Chu: ',Ch,' co: ',Dem[Ch],' ky tu' ); Writeln; Writeln('Bam phim <Enter> de ket thuc'); Readln End. {$V-} Var w,St:String; Procedure TachTu(Var Td:String; Dong:String); Var i:Integer; Begin i:=1; Td:=' '; While ((UpCase(Dong[i]) < 'A') Or (UpCase(Dong[i]) > 'Z')) And (I <=Length(Dong)) Do i:=i+1; While ((UpCase(Dong[i]) >= 'A') And (UpCase(Dong[i]) <= 'Z')) And (I <=Length(Dong)) Do Begin Td:=Td+Dong[i]; i:=i+1; End; End; {---------------------------} BEGIN Write('-Nhap mot dong: '); Readln(St); TachTu(W,St); Write(W); Readln END. Program Dem_Tu; {$V-} Var St:String; Function Sochu(Dong:String):Integer; Var dem,i:Integer;

Begin Dem:=0; i:=1; Repeat While ((UpCase(Dong[i]) < 'A') Or (UpCase(Dong[i]) > 'Z')) And (I <=Length(Dong)) Do i:=i+1; If i <= Length(Dong) Then Dem:=Dem + 1; While ((UpCase(Dong[i]) >= 'A') And (UpCase(Dong[i]) <= 'Z')) And (I <=Length(Dong)) Do i:=i+1; Until i > Length(Dong); Sochu:=Dem; End; {---------------------------} BEGIN Write('-Nhap mot cau ca dao tuc ngu: '); Readln(St); Writeln('-Cau nay co: ',Sochu(St),' tu'); Readln END. Program Tim_chuoi; Var St1,St2:String; i,sl:Integer; Begin Writeln('TIM CHUOI HAI XUAT HIEN TRONG CHUOI MOT'); Writeln(' --------------'); Writeln; Write('-Chuoi thu nhat: '); Readln(St1); Write('-Chuoi thu hai : '); Readln(St2); sl:=0; For i:=1 To Length(St1) Do If St2 = Copy(St1,i,Length(St2)) Then sl:=sl+1; Writeln; Writeln('+Chuoi thu 2 xuat hien: ',sl:2,' lan trong chuoi 1'); Writeln; Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Program Tim_Xoa; Var St,St1:String; Ch:Char; i,l,l1:Byte;

Begin Writeln('TIM VA XOA CAC KY TU TRUNG NHAU TRONG CHUOI'); Writeln(' -----------------'); Writeln; Write('-Nhap mot chuoi: '); Readln(St); St1:=St; i:=1; l:=Length(St); While i <= l Do Begin i:=i+1; If St[i]=St[i - 1] Then Begin Writeln('+Ky tu thu: ',i:2,' la: ',St[i],' bi trung lap'); Write('Ban co muon xoa ky tu nay khong (c/k)'); Readln(Ch); If UpCase(Ch)='C' Then Begin Delete(St,i,1); i:= i - 1; End; End; End; l1:=Length(St); Writeln; Writeln('+Chuoi ban dau : ',St1,' co: ',l:2,' ky tu'); Writeln(' Sau khi xoa ky tu trung nhau'); Writeln(' Chuoi con lai: ',St,' gom: ',l1:2,' ky tu'); Writeln; Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Program Ngat_tu; V ar St:String; Begin Writeln('NGAT TUNG TU TRONG CAU'); Writeln(' --------------'); Writeln; Write('-Nhap mot cau: '); Readln(St); Repeat While (St[1] =' ') And (Length(St) <> 0) Do Delete(St,1,1); While (St[1] <> ' ') And (Length(St) <>0) Do Begin Write(St[1]); Delete(St,1,1); End;

Writeln; Until Length(St)=0; Readln End. Program Cung_Ky_Tu; Var St1,St2:String; Dung:Boolean; i:Integer; Begin Writeln('KIEM TRA KY TU TRUNG CUA 2 CHUOI'); Writeln(' --------------'); Writeln; Write('-Nhap chuoi 1: '); Readln(St1); Write('-Nhap chuoi 2: '); Readln(St2); Dung:=False; If Length(St1)=Length(St2) Then Begin Dung:=True; For i:= 1 To Length(St1) Do If Pos(St1[i],St2) = 0 Then Dung:=False Else Delete(St2,Pos(St1[i],St2),1); End; If Dung Then Writeln('+Hai chuoi co cung cac ky tu') Else Writeln('+Hai chuoi co cac ky tu khac nhau'); Readln End. Program Chuoi_Doi_Xung; Var St:String; l,i:Integer; Dung:Boolean; Begin Writeln('KIEM TRA CHUOI DOI XUNG'); Writeln(' -------------'); Writeln; Write('-Nhap chuoi: '); Readln(St); l:=Length(St); Dung:=True; For i:=1 To (l Div 2) Do If St[i] <> St[l-i+1] Then Dung:=False; If Dung Then

Writeln('+Chuoi nay doi xung') Else Writeln('+Chuoi nay khong doi xung'); Readln End. Program Chen; Var i,spt:Integer; so,vitri:Integer; a:Array[1..100] Of Integer; Begin Writeln('CHEN MOT SO VAO MANG'); Writeln('--------------------'); Write('-Co bao nhieu phan tu: '); Readln(spt); For i:=1 To spt Do Begin Write('-Phan tu A[',i,']= '); Readln(a[i]); End; Writeln; Writeln('MANG TRUOC KHI CHEN'); For i:=1 To spt Do Write(a[i]:6); Writeln; Write('-Can che so: '); Readln(so); Write('-Vao vi tri: '); Readln(vitri); For i:=spt+1 Downto Vitri+1 Do a[i]:=a[i-1]; a[vitri]:=so; spt:=spt+ 1; Writeln; Writeln('MANG SAU KHI CHEN'); For i:=1 To spt Do Write(a[i]:6); Readln End. Program Xoa_Pt; Var i,spt,vitri:Integer; a:Array[1..100] Of Integer; Begin Writeln('XOA PHAN TU TRONG MANG'); Writeln('----------------------'); Writeln; Write('-Mang co bo nhieu phan tu: '); Readln(spt); For i:=1 To spt Do

Begin Write('-Phan tu A[',i:2,']= '); Readln(a[i]); End; Writeln; Writeln(' MANG TRUOC KHI XOA'); Writeln(' -----------------'); Writeln; For i:=1 To spt Do Write(a[i]:6); Writeln; Writeln; Write('-Vi tri muon xoa: '); Readln(vitri); For i:=vitri to spt - 1 Do a[i]:=a[i+1]; spt:=spt - 1; Writeln; Writeln(' MANG SAU KHI XOA'); Writeln(' ----------------'); Writeln; For i:= 1 to spt Do Write(a[i]:6); Writeln; Writeln; Writeln(' Bam phim <Enter> de ket thuc '); Readln End. Program Da_thuc; Var a:Array[1..255] Of Real; i,n:Byte; x,p:Real; Begin Writeln('TINH GIA TRI CUA DA THUC BAC N'); Writeln('------------------------------'); Writeln; Write('-Cho biet bac cua da thuc: '); Readln(n); For i:= N Downto 0 Do Begin Write('-Cho biet he so A[',i:2,']= '); Readln(a[i]); End; Writeln; Write('-Cho biet X= '); Readln(x); P:=a[n]; For i:= N Downto 1 Do P:=x * p + a[i-1];

Writeln; Writeln('+Tri cua da thuc P(x)= ',P:0:6); Writeln; Writeln(' Bam phim <Enter> de ket thuc '); Readln End. Program Tim_so; Var a:Array[1..4,1..6] Of Integer; i,j,so,solan:Integer; Begin Writeln('TIM MOT SO TRONG MANG'); Writeln('---------------------'); Writeln; For i:=1 To 4 Do For j:=1 to 6 Do Begin Write('-Phan tu A[',i,',',j,']= '); Readln(a[i,j]); End; Writeln; Write('-So muon tim: '); Readln(so); solan:=0; For i:=1 To 4 Do For j:=1 To 6 Do If so=a[i,j] Then Begin solan:=solan+1; Writeln('+Lan: ',solan,' tai hang: ',i,' cot: ',j); End; Writeln; Writeln('+Tong so lan xuat hien la: ',solan); For i:=1 To 4 Do Begin For j:=1 To 6 Do Write(a[i,j]:8); Writeln; End; Readln End. Program Mang_tang; Const Max=10; Var a:Array[1..Max] Of Integer; i,j,tam:Integer; Begin Writeln('SAP XEP MANG TANG DAN'); Writeln('---------------------');

Writeln; For i:= 1 To Max Do Begin Write('-Phan tu A[',i,']= '); Readln(a[i]); End; For i:=1 to Max-1 Do For j:= i+1 To Max Do Begin If a[i] > a[j] Then Begin tam:=a[i]; a[i]:=a[j]; a[j]:=tam; End; End; Writeln; Writeln('+Mang sau khi sap xep:'); Writeln; For i:=1 To Max Do Write(a[i],' '); Writeln; Readln End. Program Bo_so_trung; Const Max=100; Var a:Array[1..Max] Of Integer; i,j,k,n:Integer; Begin Writeln('XOA BO CAC SO TRUNG NHAU'); Writeln('------------------------'); Writeln; Write('-Nhap so phan tu mang: '); Readln(n); For i:=1 To N Do Begin Write('-Phan tu A[',i,']= '); Readln(a[i]); End; i:=2; While i <= N Do Begin j:=1; While a[j] <> a[i] Do j:=j+1; If j < i Then Begin For k:=i to n-1 Do

a[k]:= a[k+1]; n:=n-1; End Else i:=i+1; End; Writeln; Write('-Mang con lai: '); For i:=1 to n Do Write(a[i]:8); Writeln; Writeln(' Bam phim <Enter> de ket thuc '); Readln End. Program Day_con; Const k=10; a:Array[1..k] Of Integer=(1,3,2,8,10,12,7,29,6,3); Var i:Integer; vt,max:Integer; n,tong:Integer; Begin Vt:=1; max:=a[1]; n:=1; tong:=a[1]; For i:=2 To k Do Begin If (a[i] > a[i-1]) Then tong:=tong+a[i]; If (a[i] < a[i-1]) Or (i=k) Then Begin If tong > max Then Begin max:=tong; vt:=n; End; n:=i; tong:=a[i]; End; End; Writeln('-Day con la: '); i:=vt; Repeat Write(a[i]:6); max:=max-a[i]; i:=i+1; Until max=0; Writeln;

Writeln(' Bam phim <Enter> de ket thuc '); Readln End. Program Gt_Chon; Uses Crt; Const Max=10; Type Hoten=String[24]; Mang = Array[1..Max] Of Hoten; Var Hs:Mang; So:Byte; {-------------------} Function ChuHoa(St:String):String; Var i:Byte; Begin For i:=1 To Length(St) Do St[i] := UpCase(St[i]); ChuHoa:=St; End; {-------------------} Function Behon(Var X,Y : Hoten): Boolean; Begin Behon:= ChuHoa(X) < ChuHoa(Y); End; {-------------------} Procedure Hoanvi(Var X,Y : Hoten); Var Tam:Hoten; Begin Tam:=X; X:=Y; Y:=Tam; End; {-------------------} Procedure Chon(Var A: Mang; n: Byte); Var i,j:Byte; Begin For i:=1 To N-1 Do For j:= i To n Do If Behon(A[j], A[i]) Then Hoanvi(A[i], A[j]); End; {-------------------} Procedure Nhap(Var A: Mang; Var N: Byte); Var Ch:Char;

i:Byte; Begin i:=1; Writeln(' NHAP DANH SACH: ',MAX:2,' NGUOI'); Writeln(' ----------------'); Write('-Nhap ho ten nguoi thu: ',i:2,' = '); Readln(a[i]); While i < Max Do Begin i:=i+1; Write('-Nhap ho ten nguoi thu: ',i:2,' = '); Readln(a[i]); End; n:=i; Writeln; Write(' *Bam phin <Enter> de xem danh sach sap xep'); Readln End; {-------------------} Procedure Xuat(A:Mang; N: Byte); Var i:Byte; Begin For i:= 1 to N Do Writeln(a[i]); End; {-------------------} BEGIN ClrScr; Writeln('GIAI THUAT CHON'); Writeln('---------------'); Nhap(Hs, so); Chon(Hs,so); Xuat(Hs,so); Writeln(' Bam phim <Enter> de ket thuc'); Readln END.