You are on page 1of 24

bi: Nhp vo mt mng gm n s nguyn v s nguyn k. Tm v a ra mn hnh: a.Gi tr ln nht ca mng, v tr ln nht b. Ga tr nh nht ca mng, v tr c.

. Tnh tng bnh phng cc gi tr v tr chn d. Sp xp mng theo th t tng dn e. m xem trong mang c bao nhiu gi tr bng k. var a:array[1..200] of integer; max,min,m,j,n,imin,imax,d,k,s,tg:integer; Begin write('Nhap so phan tu:');readln(n); write('Nhap k:'); readln(k); for m:=1 to n do begin write('Nhap a[',m,']=');readln(a[m]); end; max:=a[1];min:=a[1];d:=0;s:=0;imin:=1;imax:=1; for m:= 2 to n do begin if a[m]>max then begin max:=a[m]; imax:=m; end; if a[m]<min then begin min:=a[m]; imin:=m; end; if a[m]=k then d:=d+1; if m mod 2=0 then s:=s+sqr(a[m]); end; {sx day tang dan} For m:=1 to n-1 do For j:=m+1 to n do if a[m]>a[j] then begin tg:=a[m]; a[m]:=a[j]; a[j]:=tg; end; Writeln('Gia tri lon nhat cua day la ', max,' o vi tri',imax); Writeln('Gia tri nho nhat cua day la ', min,' o vi tri',imin); Writeln('Tong binh phuong cac so o vi tri chan ',s); writeln('So phan tu co gia tri bang ',k,' la ',d); Writeln('Mang sau khi sap xep'); for m:=1 to n do

write(a[m]); readln; End. {Tim doan dai nhat gom cac so 0 lien tiep} var a:array[1..100] of integer; n,dem,i,j,tong,max,vt:integer; begin write('Nhap so phan tu cua mang:');readln(n); for i:=1 to n do begin write('Nhap a[',i,']:');readln(a); end; dem:=0; for i:=1 to n do begin if a =0 then dem:=dem+1 else dem:=0; if dem>max then max:=dem; end; write('Doan dai nhat gom cac so 0 lien tiep la ',max); readln; end. {Kiem tra mot day la cap so cong} var a:array[1..100] of integer; d,i,n:integer; kt:boolean; begin write('Nhap n:');readln(n); for i:=1 to n do begin write('Nhap a[',i,']:');readln(a); end; kt:=true;i:=3; d:=a[2]-a[1]; while (i<=n) do begin if a-a[i-1] <>d then kt:=false; inc(i); end; if kt then write('day la cap so cong') else write('day khong la csc'); readln; end. {Tim day con tang co tong lon nhat, in ra day con do} var a:array[1..100] of integer; n, i,j,tong,max,vt:integer; begin

write('Nhap so phan tu cua mang:');readln(n); for i:=1 to n do begin write('Nhap a[',i,']:');readln(a); end; i:=1;max:=0; while (i<=n) do begin j:=i+1;tong:=a; while (j<=n) and (a[j]>a[j-1]) do begin tong:=tong+a[j]; if tong>max then begin max:=tong; vt:=i; end; inc(j); end; tong:=0; inc(i); end; writeln('Day co tong tang lon nhat'); while (vt<=n) and (a[vt]<a[vt+1]) do begin write(a[vt]); vt:=vt+1; end; writeln(a[vt]); write('Voi tong lon nhat la ',max); readln; end. {Tron hai mang duoc sap xep tang dan thanh mot mang duoc sap xep tang dan} WriteLN('NHAP PHAN TU CHO MANG A:'); Writeln('_________________________'); write('Nhap n:');readln(n); for i:=1 to n do begin write('Nhap a[',i,']:');readln(a); end; WRIteln('NHAP PHAN TU CHO MANG B:'); write('Nhap m:');readln(m); for i:=1 to m do begin write('Nhap b[',i,']:');readln(b); end; i:=1;j:=1;k:=1;

{Ca hai day chua het} while (i<=n) and (j<=m) do begin if a<b[j] then begin c[k]:=a; inc(i); end else begin c[k]:=b[j]; inc(j); end; inc(k); end; {Day b het} while (i<=n) do begin c[k]:=a; inc(i); inc(k); end; {Day a het} while (j<=m) do begin c[k]:=b[j]; inc(j); inc(k); end; WRITELN('DAY SAU KHI TRON LA'); writeln('___________________'); for k:=1 to n+m do write(c[k],' ') ;} {Tron mang theo pp chan o cuoi} {Type mang=array[1..100] of integer; var a,b,c:mang; i,m,k,n,j:integer; begin write('Nhap n:');readln(n); for i:=1 to n do begin write('Nhap a[',i,']:');readln(a); end; write('Nhap m:');readln(m); for j:=1 to m do begin write('Nhap b[',j,']:');readln(b[j]);

end; a[n+1]:=32001; b[m+1]:=32001; i:=1;j:=1; for k:=1 to m+n do begin if a<b[j] then begin c[k]:=a;inc(i);end else begin c[k]:=b[j];inc(j);end; end; writeln('Day sau khi tron la'); for k:=1 to m+n do write(c[k]);} readln; end. {Doi cho phan tu lon nhat va nho nhat} write('Nhap n:');readln(n); for i:=1 to n do begin write('Nhap a[',i,']:');readln(a); end; i:=1;j:=n;min:=a[1];max:=a[n]; while i<=n do begin if a<=min then begin min:=a; k:=i; end; inc(i); end; while j>=1 do begin if a[j]>= max then begin max:=a[j]; x:=j; end; dec(j); end; a[k]:=max; a[x]:=min; for i:=1 to n do write(a) {Tinh tong ca so nam giua so 0 dau tien va so 0 cuoi cung neu hai so 0 nam canh nhau thi ket qua se la 0} write('Nhap n:');readln(n); for i:=1 to n do

begin write('Nhap a[',i,']:');readln(a); end; i:=1;j:=n; x:=0; while (i<=n) and (a<>0) do inc(i); while (j>=1) and (a[j]<>0) do dec(j); if (j-i)>=2 then begin for k:=i to j do x:=x+a[k]; end else writeln('Tong la 0'); writeln('Tong la ',x);} {Liet ke cac so nguyen to co trong day:'} begin write('Nhap n:');readln(n); for i:=1 to n do begin write('Nhap a[',i,']:');readln(a); end; {cach 1} i:=1; while (i<=n) do begin d:=0; for j:=1 to a do if a mod j= 0 then inc(d); if d=2 then writeln(a,'la so nguyen to'); inc(i); end; {cach 2} i:=1; while (i<=n) do begin j:=2; while (a mod 2 <>0) and (j<=round(sqrt(a))) do inc(j); if j>round(sqrt(a)) then writeln(a,'la so nguyen to'); inc(i); end; {Liet ke cac so hoan hao co trong day} i:=1; while (i<=n) do begin x:=0; for j:=1 to (a div 2) do if a mod j=0 then x:=x+j; if x=a then write(a,' La so hoan hao');

inc(i); end; Bi tp Pascal ni dung v mng? 22.32pm 22-03-2010 === 1: Vit chng trnh nhp vo mt dy n s nguyn (n: hng s). In ra mn hnh cc gi tr khc nhau ca dy s ny. VD: nhp vo: 5 20 15 5 20 17 ==> In ra: 5 20 15 17 2: Cho 1 dy gm n s nguyn dng c 3 ch s, hy sp xp dy theo th t tng dn ca ch s hng n v; hng n v bng nhau th sp xp theo th t tng dn ca hng chc; hng chc bng nhau th sp xp theo th t tng dn ca hng trm. 3: Cho 2 mng A v B c sp xp theo th t tng dn. Hy trn 2 mng li vi nhau c mng th 3 l mng C vi iu kin mng C cng c sp xp theo th t tng dn ngay sau khi trn. Thanks cc bn trc! === B1: Var i,j,k,n: integer; {Coi n la bien} BEGIN Write('N=');Readln(n); For i:=1 to n do Begin Write('A[',i,']=');Readln(a[i]); End; {Duyet qua cac phan tu, neu phan tu khong trung thi in ra} For i:=1 to n do For j:=1 to n do If (i<>j) and (a[i]<>a[j]) then Write(A[i]:6); Readln; END. === Quote: c gi bi hcvtpt B1: Var i,j,k,n: integer;

{Coi n la bien} BEGIN Write('N=');Readln(n); For i:=1 to n do Begin Write('A[',i,']=');Readln(a[i]); End; {Duyet qua cac phan tu, neu phan tu khong trung thi in ra} For i:=1 to n do For j:=1 to n do If (i<>j) and (a[i]<>a[j]) then Write(A[i]:6); Readln; END. Bi ca bn khi chy khng c! Nu ly phn vd mnh a ra th N in ra hng s: 5 20 5 20 === Ci bi 1 c l nn a vo mng B xt === B1 ca bn thc ra rt d v c ti 2 cch lm C1 l gn 1 mng boolean nh du cc phn t ging nhau c in ra Var i, j, n: Integer; a: array[100] of Integer; b: array[100] of Boolean; Begin Readln(n); for i := 1 to n do Readln(a[i]); for i := 1 to n do b[i] := True; for i := 1 to n do if b[i] then Begin Write(a[i]:6); for j := i + 1 to n do if a[i] = a[j] then b[j] := False; End; Readln; End. C2 l duyt ngc v sau xem phn t xut hin cha Var i, j, n: Integer; a: array[100] of Integer;

Begin Readln(n); for i := 1 to n do Readln(a[i]); Write(a[1]:6); for i := 2 to n do Begin for j := 1 to i - 1 do if a[i] = a[j] then continue; Write(a[i]:6); End; Readln; End. === Cm n cc bn nh! Hai cu cn li mong cc bn gip , mnh ang cn gp v sp ti mnh phi thi Pascal ri! === bi 1 Code: uses crt; var a:array[1..100] of integer; i,n:integer; t:set of byte; begin clrscr; write('nhap so pt cua day : ');readln(n); writeln('nhap day : '); for i:=1 to n do readln(a[i]); write('cac so khac nhau trong day : '); for i:=1 to n do if not (a[i] in t) then begin write(a[i],' '); t:=t+[a[i]]; end; readln; end. bi 3 Code: uses crt; var a:array[1..100] of integer; i,j,n,t:integer; begin clrscr; {--- nhap mang a ---} write('nhap so pt cua a : ');readln(n); write('nhap day a : '); for i:=1 to n do readln(a[i]); {--- nhap mang b noi vao mang a ---} write('nhap so pt cua b : ');readln(n); write('nhap day b : '); for j:=i+1 to i+n do readln(a[j]); {--- sap xep lai mang ---} n:=j; for i:=1 to n-1 do for j:=i+1 to n do if a[i]>a[j] then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; end; clrscr; {--in ket qua ---} for i:=1 to n do write(a[i],' '); readln; end.

=== Mnh xin ngh cch sau: Program mang; uses crt; var A:array[1..100] of integer; i,n,Tg:integer; Begin clrscr; Write('Nhap so luong phan tu cua mang, n= '); readln(n); for i:=1 to n do begin write('nhap phan tu thu ',i,' vao: '); readln(A[i]); end; {Sap xep mang thanh day khong giam} for i:=1 to n-1 do if A[i+1] < A[i]then begin Tg:=A[i+1]; A[i+1]:=A[i]; A[i]:=Tg; end; writeln(' Cac gia tri khac nhau trong mang la: '); for i:=1 to do if A[i] < A[i+1] then write(A[i]:5); readln end. === Hi cch ca pc cng hay (chp d ci ^^ ). h theo em pc nn i ch If A[i]A[i+1].. s d nh hn . === Quote: c gi bi kengumuoiTH Mnh xin ngh cch sau: writeln(' Cac gia tri khac nhau trong mang la: '); for i:=1 to do if A[i] < A[i+1] then write(A[i]:5); readln end. th cch ca bn cng ging cch ca mnh thi. ch khc nhau ch sp xp. cn on cui yu cu in ra mng c sp xp ch c bo in ra

nhng phn t khc nhau u === uses crt; var A,B:array[1..100] of integer; C:array[1..200] of integer; i,n,m,temp,k,j:integer; begin clrscr; repeat write('Nhap so phan tu cua mang A: ');readln(n); write('Nhap so phan tu cua mang B: ');readln(m); until (N>0) and (N<101) and (M>0) and (M<101); for i:=1 to n do begin write('A[',i,']= ');readln(A[i]); end; for i:=1 to m do begin write('B[',i,']= ');readln(B[i]); end; {sap xep mang A,B} for i:=1 to n-1 do for j:=i+1 to n do if A[i]>A[j] then begin temp:=A[i]; A[i]:=A[j]; A[j]:=temp; end; for i:=1 to m-1 do for j:=i+1 to m do if A[i]>A[j] then begin temp:=B[i]; B[i]:=B[j]; B[j]:=temp; end; {noi mang A va B vao mang C} i:=1;j:=1;k:=1; while (i<=n) and (j<=m) do if A[i]>B[j] then begin C[k]:=B[j]; inc(j);inc(k); end

else begin C[k]:=A[i]; inc(i);inc(k); end; while i<=n do begin C[k]:=A[i]; inc(i);inc(k); end; while j<=m do begin C[k]:=B[j]; inc(j);inc(k); end; write('Mang C= '); for k:=1 to m+n do write(C[k],' '); readln end.

Program PTB2;

Var a,b,c:Integer; delta,x1,x2:Real; Begin Writeln('GIAI PHUONG TRINH BAC HAI'); Writeln(' --------------'); Repeat Write('-Nhap he so a= '); Readln(a); Until a <>0; Write('-Nhap he so b= '); Readln(b); Write('-Nhap he so c= '); Readln(c); delta:=b*b-4*a*c; If delta < 0 Then Writeln('*Phuong trinh vo nghiem') Else If delta = 0 Then Writeln('*Phuong trinh co 2 nghiem bang nhau X= ',-b/2*a:6:2) Else

Begin x1:=(-b-sqrt(delta))/2*a; x2:=(-b+sqrt(delta))/2*a; Writeln('*Nghiem thu nhat X1= ',x1:6:2); Writeln('*Nghiem thu hai X2= ',x2:6:2); End; readln End. **********0102********** Program Ao_thu; Begin Writeln(' BAI THO AO THU'); Writeln('Ao thu lanh leo nuoc trong veo'); Writeln('Mot chiec thuyen cau be teo teo'); Writeln('Song biec theo lan hoi gon ty'); Writeln('La vang truoc gio se dua veo'); Writeln(' NGUYEN KHUYEN'); Readln End. **********0103********** Program So_hoc; Var so1,so2,tong,hieu,tich:Integer; thuong:Real; Begin Write('-Nhap so thu nhat = '); Readln(so1); Write('-Nhap so thu hai = '); Readln(so2); tong := so1 + so2; hieu := so1 - so2; tich := so1 * so2; thuong := so1 / so2; Writeln('*Tong cua hai so ',so1,' va ',so2,' = ',tong); Writeln('*Hieu cua hai so ',so1,' va ',so2,' = ',hieu); Writeln('*Tich cua hai so ',so1,' va ',so2,' = ',tich); Writeln('*Thuong cua hai so ',so1,' va ',so2,' = ',thuong:6:2); Readln End. **********0104********** Program Pithagore; Var a,b :Integer; c:Real; Begin Writeln(' CHUONG TRINH TINH CANH HUYEN TAM GIAC VUONG');

Writeln(' theo dinh ly Pithagore'); Write('-Nhap canh a = '); Readln(a); Write('-Nhap canh b = '); Readln(b); c := Sqrt((a*a) + (b*b)); Writeln('*Canh huyen = ',c:6:2); Readln End. **********0105********** Program Phep_Cong; Var so1,so2,so3,tong :Integer; Begin Writeln(' CHUONG TRINH THUC HIEN PHEP CONG SO HOC'); Writeln(' co toi da 4 ky so'); Write('-Nhap so thu nhat = '); Readln(so1); Write('-Nhap so thu hai = '); Readln(so2); Write('-Nhap so thu ba = '); Readln(so3); tong:= so1+so2+so3; Writeln; Writeln; Writeln('-------------------------------'); Writeln; Writeln(' ',so1:4); Writeln(' + ',so2:4); Writeln(' ',so3:4); Writeln(' -----'); Writeln(' = ',tong:5); Readln End. **********0106********** Program Lenh_Write; Begin Write('Nam '); Write('Quoc '); Write('Son '); Write('Ha '); Write('Nam '); Write('De '); Write('Cu '); Readln End.

**********0107 Program Lenh_Writeln; Begin Writeln('Nam '); Writeln('Quoc '); Writeln('Son '); Writeln('Ha '); Writeln('Nam '); Writeln('De '); Writeln('Cu '); Readln End. *********0108********* Program Tam_giac_Pascal; Begin Writeln(' 1'); Writeln(' 1 1'); Writeln(' 1 2 1'); Writeln(' 1 3 3 1'); Writeln('1 4 6 4 1'); Readln End. *********0109********* Program Hinh_tron; Var r:Integer; s:Real; Begin Writeln('CHUONG TRINH TINH DIEN TICH HINH TRON'); Write('-Cho biet ban kinh = '); Readln(r); s:=3.1416 * r * r; Writeln('*Dien tich hinh tron = ',s:6:2,' met vuong'); Readln End. *********0110********** Program Khuon_dang; Var ky_tu :Char; chuoi :string[24]; so_nguyen:Integer; so_thuc:Real; Begin Writeln('CHUONG TRINH XUAT DU LIEU THEO KHUON DANG'); Write('-Nhap mot ky tu = '); Readln(ky_tu); Write('-Nhap ho ten = ');

Readln(chuoi); Write('-Nhap mot so nguyen = '); Readln(so_nguyen); Write('-Nhap mot so thuc = '); Readln(so_thuc); Writln; Writeln('------------------------------'); Writeln('XUAT DU LIEU RA MAN HINH'); Writeln(ky_tu); Writeln(chuoi); Writeln(so_nguyen); Writeln(so_thuc); Readln End.

o o

13-03-2009 0:59 o KhanhTK

Tr li ti Hi p: Mt s bi tp mu trong PASCAL Tr li - Tho lun Lin h BI TP MU

o o o

Bi tp 5.1: Vit chng trnh tm gi tr ln nht Gia nhp ngy ca mt mng cha cc s nguyn gm N phn t. tng: 24-02-2009 o S bi vit 28 - Cho s ln nht l s u tin: Max:=a[1]. - Duyt qua cc phn t a[i], vi i chy t 2 ti N: Nu a[i]>Max th thay Max:=a[i]; o im 355 Uses Crt; Type Mang = ARRAY[1..50] Of Integer; Var A:Mang; N,i,Max:Integer; Begin {Nhp mng} Write(Nhap N=); Readln(N); For i:=1 To N Do Begin Write(A[,i,]=); Readln(A[i]); End; {Tm phn t ln nht} Max:=A[1];

For i:=2 To N Do If Max {In kt qu ra mn hnh} Writeln(Phan tu lon nhat cua mang: , Max); Readln; End. Bi tp 5.2: Vit chng trnh tnh tng bnh phng ca cc s m trong mt mng gm N phn t. tng: Duyt qua tt c cc phn t A[i] trong mng: Nu A[i]<0 th cng dn (A[i])2 vo bin S. Uses Crt; Type Mang = ARRAY[1..50] Of Integer; Var A:Mang; N,i,S:Integer; Begin {Nhp mng} Write(Nhap N=); Readln(N); For i:=1 To N Do Begin Write(A[,i,]=); Readln(A[i]); End; {Tnh tng} S:=0; For i:=1 To N Do If A[i]<0 Then S:=S+A[i]*A[i]; {In kt qu ra mn hnh} Writeln(S= , S); Readln; End. Bi tp 5.3: Vit chng trnh nhp vo mt mng gm N s nguyn. Sp xp li mng theo th t tng dn v in kt qu ra mn hnh. tng: Cho bin i chy t 1 n N-1, ng thi cho bin j chy t i+1 n N: Nu A[i]>A[j] th i ch A[i], A[j]. Uses Crt; Type Mang = ARRAY[1..50] Of Integer; Var A:Mang; N,i,j,Tam:Integer; Begin {Nhp mng}

Write(Nhap N=); Readln(N); For i:=1 To N Do Begin Write(A[,i,]=); Readln(A[i]); End; {Sp xp} For i:=1 To N-1 Do For j:=i+1 To N Do If A[i]>A[j] Then Begin Tam:=A[i]; A[i]:=A[j]; A[j]:=Tam; End; {In kt qu ra mn hnh} Writeln(Ket qua sau khi sap xep:); For i:=1 To N Do Write(A[i]:5); Readln; End. Bi tp 5.4: Vit chng trnh nhp vo mt mng A gm N s nguyn v nhp thm vo mt s nguyn X. Hy kim tra xem phn t X c trong mng A hay khng? tng: Dng thut ton tm kim tun t. So snh x vi tng phn t ca mng A. Thut ton dng li khi x=A[i] hoc i>N. Nu x=A[i] th v tr cn tm l i, ngc li th kt qu tm l 0 (khng tm thy). Uses Crt; Type Mang = ARRAY[1..50] Of Integer; Var A:Mang; N,i,x:Integer; Function TimKiem(x, N: Integer; A:Mang):Integer; Var i:Integer; Begin I:=1; While (I <= N) and (X<>A[I]) do I:=I+1; If I <= N Then Timkiem:=I Else Timkiem:=0; End; Begin

{Nhp mng} Write(Nhap N=); Readln(N); For i:=1 To N Do Begin Write(A[,i,]=); Readln(A[i]); End; Write(Nhap X=); Readln(x); {Kt qu tm kim} If TimKiem(X,N,A)<>0 Then Writeln(Vi tri cua X trong mang la:, TimKiem(X,N,A)) Else Writeln(X khong co trong mang.); Readln; End. Bi tp 5.5: Gi s mng A c sp xp theo th t tng dn. Vit hm kim tra xem phn t X c trong mng A hay khng? tng: So snh x vi phn t gia mng A[giua]. Nu x=A[giua] th dng (v tr cn tm l ch s ca phn t gia ca mng). Ngc li, nu x>A[giua] th tm on sau ca mng [giua+1,cuoi], ngc li th tm on u ca mng [dau,giua-1]. Sau y l hm ci t cho thut ton ny: Function TimKiemNhiPhan(X, N: Integer; A: Mang):Integer; Var dau,cuoi,giua:Integer; Found:Boolean; Begin dau:=1; {im mt tri ca khong tm kim} cuoi:=N; {im mt phi ca khong tm kim} Found:=False; {cha tm thy} While (dau <=cuoi) and (Not Found) Do Begin giua:=(dau + cuoi) Div 2; If X = A[giua] Then Found:=True { tm thy} Else If X > A[giua] Then dau:=giua+1

Else cuoi:=giua-1; End; If Found Then TimKiemNhiPhan:= giua Else TimKiemNhiPhan:=0; End; Bi 1:Trch thi hc sinh gii lp 9 Mt bn c 8 nhn 8 vung mi c nh a ch l cp s (x;y), (trong :x l s th t ca hng t 1 n 8tnh t trn xung; y s th t ca ct t 1 n 8 tnh t tri qua phi).Trn bn c c t trc cc ch chut my mt s .Mt ch mo my c th nhn thy cc ch chut ny nu chut cng nm trn mt ng vi n hoc cng mt ng cho vi n.Xc nh v tr t 1 ch mo my sao cho n c th nhn thy tt c ch chut my c trn bn c Yu cu: Nhp N cp s nguyn (x,y) th hin a ch ca cc ch chut my t trn bn c Vit ra v tr t ch mo my tha mn dk trn. V d Vi N=4 v v tr chut Th kt qu ta ca mo l (6;3) M: Program Meo_bat_chuot; Uses crt; Type banco=array[1..8,1..8] of integer; Var a:banco; hang,cot,n,i,j,c,x,y,max:integer; ch:char; Procedure chuyen(var hang,cot:integer); Var i,j,htam1,htam2,ctam1,ctam2:integer; Begin htam1:=hang;ctam1:= cot; htam2:= hang;ctam2:=cot; {------------------------------------------} For i:=1 to 8 do a[hang][i]:=a[hang][i]+1; {------------------------------------------} For i:=1 to 8 do a[i][cot]:=a[i][cot]+1; a[hang][cot]:=a[hang][cot]-1; {-------------------------------------------

------------CHUYEN DUONG CHEO /------------------------------------------------------} While (htam1<>1) and (ctam1<>8) do Begin htam1:=htam1-1; ctam1:=ctam1+1; a[htam1][ctam1]:=a[htam1][ctam1]+1; End; While (ctam2<>1) and (htam2<>8) do Begin htam2:=htam2+1; ctam2:=ctam2-1; a[htam2][ctam2]:=a[htam2][ctam2]+1; End; {------------------------------------------------------CHUYEN DUONG CHEO \------------------------------------------------------} htam1:=hang;ctam1:=cot; htam2:=hang;ctam2:=cot; While (htam1<>1) and (ctam1<>1) do Begin htam1:=htam1-1; ctam1:=ctam1-1; a[htam1][ctam1]:=a[htam1][ctam1]+1; End; While (htam2<>8) and (ctam2<>8) do Begin htam2:=htam2+1; ctam2:=ctam2+1; a[htam2][ctam2]:=a[htam2][ctam2]+1; End; End; Begin Repeat clrscr; Writeln('Le Manh Chuc - Lop 9/1 - Truong THCS Kim Dong'); Writeln('---------------------------------------------'); For i:=1 to 8 do For j:=1 to 8 do a[i,j]:=0; Repeat Write('Nhap so chuot: '); Readln(n); Until n<=64; For c:=1 to n do Begin

Repeat Write('Nhap so hang cua chuot ',c,':'); Readln(hang); Until (1<=hang) and (hang<=8); Repeat Write('Nhap so cot cua chuot ',c,':'); Readln(cot); Until (1<=cot) and (cot<=8); chuyen(hang,cot); End; Max:=a[1,1]; For i:=1 to 8 do For j:=1 to 8 do If max<a[i,j] then Begin max:=a[i,j]; x:=i; y:=j; End; If max=n then Writeln('Toa do cua meo la (',x,';',y,')') Else Writeln(#7,'Ko tim thay'); Writeln; Write('Ban co muon tiep tuc nua khong (c/k):'); Readln(ch); Until Upcase(ch)='K'; End. Nhp vo hai s t nhin M v N. Kim tra xem c th nhn c s M t s N bng cch xa b bt mt s ch s no trong biu din ca N hay khng? V D: M=1357. N=105325896720. => N xa b ln lt t tri sang phi cc s 0,5,2,8,9,6,2 v 0 th c M. M=1357. N=105725896720. => Khng c. trong trng hp c th nhn c M t N th vit li N sao cho cc ch s cn xa c vit bng mu trn nn xanh, cn cc ch s cn li c vit bi mu vng trn nn xanh. uses CRT; 2.var 3. M, N: String; 4. C: array[1..255] of Boolean; 5. 6. function Check(M, N: String): Boolean; 7.var
1.

8. i, k: Integer; 9.begin 10. k:=0; 11. Check:=False; 12. for i:=1 to Length(M) do 13. begin 14. if k = Length(N) then Exit; 15. while k < Length(N) do 16. begin 17. Inc(k); 18. if M[i] = N[k] then 19. begin 20. C[k]:=True; 21. Break; 22. end; 23. end; 24. end; 25. Check:=True; 26. end; 27. 28. procedure Init; 29. begin 30. FillChar(C, SizeOf(C), False); 31. end; 32. 33. procedure WriteResult; 34. var 35. i: Integer; 36. begin 37. TextBackground(Green); 38. for i:=1 to Length(N) do 39. if C[i] then 40. begin 41. TextColor(Yellow); 42. Write(N[i]); 43. end 44. else 45. begin 46. TextColor(Red); 47. Write(N[i]); 48. end; 49. end; 50. 51. begin 52. Init; 53. Write('M = '); ReadLn(M); 54. Write('N = '); ReadLn(N);

if Check(M, N) then WriteResult 56. else WriteLn('M khong thuoc N'); 57. ReadLn; 58. end.
55.

You might also like