pqtoan Admin
Posts : 76 Danh tiếng : 3 Join date : 10/11/2014
| Tiêu đề: đề pgd diên khánh 21/2/2017, 08:16 | |
| | |
|
nhathuyvanlang
Posts : 49 Danh tiếng : 9 Join date : 26/03/2016
| Tiêu đề: Re: đề pgd diên khánh 22/2/2017, 07:36 | |
| Bài 2: - Code:
-
uses crt; var a:array[1..100] of integer; i,n,j,k,t:integer; begin clrscr; write('nhap so phan tu cau day:');readln(n); for i:=1 to n do begin write('a[',i,']:');readln(a[i]); end; write('nhap so k:');readlN(K); for i:=1 to n do begin if a[i]>0 then t:=t+1 else t:=0; if t=k then begin write('co'); readln; exit; end; end; write('khong co'); readln; end. | |
|
nhathuyvanlang
Posts : 49 Danh tiếng : 9 Join date : 26/03/2016
| Tiêu đề: Re: đề pgd diên khánh 22/2/2017, 07:52 | |
| Bài 3: - Code:
-
uses crt; var a:array[1..100,1..100] of integer; i,n,j,k,m:integer; begin clrscr; write('nhap bac ma tran:');readln(n); for i:=1 to n do for j:=1 to n do if (i mod 2<>0) and (j mod 2<>0) then a[i,j]:=1 else if (i mod 2=0) and (j mod 2=0) then a[i,j]:=-1 else a[i,j]:=0; writeln; m:=0; for i:=1 to n do begin for j:=1 to n do write(a[i,j]:3); writeln; end; for i:=1 to n do for j:=1 to n do m:=m+a[i,j]; writeln('tong la:',m); readln; end.
| |
|
nhathuyvanlang
Posts : 49 Danh tiếng : 9 Join date : 26/03/2016
| Tiêu đề: Re: đề pgd diên khánh 22/2/2017, 08:23 | |
| Bài 4: - Code:
-
Program COUNTPL; Const maxN =255; Var n :Byte; S :String; Free :Array[1..maxN,1..maxN] of Boolean; F :Array[0..maxN] of Byte; procedure Init; var i,j,k :Byte; begin n:=Length(S); for i:=1 to n do for j:=1 to n do if (j=i) or (j=i-1) then Free[i,j]:=true else Free[i,j]:=false; for k:=1 to n-1 do for i:=1 to n-k do begin j:=i+k; Free[i,j]:=(S[i]=S[j]) and (Free[i+1,j-1]); end; end; procedure Optimize; var i,j :Byte; begin F[0]:=0; for i:=1 to n do begin F[i]:=i; for j:=1 to i do if (Free[j,i]) and (F[i]>F[j-1]+1) then F[i]:=F[j-1]+1; end; end; Begin Assign(Input,''); Reset(Input); Assign(Output,''); Rewrite(Output); Read(S); Init; Optimize; Write(F[n]); Close(Input); Close(Output); End. | |
|
Sponsored content
| Tiêu đề: Re: đề pgd diên khánh | |
| |
|