Skip to content

Instantly share code, notes, and snippets.

@realhaidinh
Last active April 6, 2019 15:25
Show Gist options
  • Save realhaidinh/3ff1802061740fb6ac9eb8cb1325e099 to your computer and use it in GitHub Desktop.
Save realhaidinh/3ff1802061740fb6ac9eb8cb1325e099 to your computer and use it in GitHub Desktop.
Pascal
program bangsolieu;
uses crt;
var x,y,i,j,k,m,l:integer;
a:array[1..100,1..100] of integer;
b:array[1..10] of integer;
khong,mot,hai,ba,bon,nam,sau,bay,tam,chin:boolean;
BEGIN
clrscr;
repeat
begin
write('So hang:');readln(x);
write('So cot:');readln(y);
end;
until (x>0) and (x<=100) and (y>0) and (y<=100);
for i:=1 to x do
for j:=1 to y do
begin
write('a[',i,',',j,']=');readln(a[i,j]);
end;
for i:=1 to x do
begin
for j:=1 to y do write(a[i,j]:3,' ');
writeln;
end;
writeln;
{Kiem tra co phan tu tu 0-9 hay khong}
for i:=1 to x do
for j:=1 to y do
if a[i,j]= 0 then khong:=true
else if a[i,j]=1 then mot:=true
else if a[i,j]= 2 then hai:=true
else if a[i,j]= 3 then ba:=true
else if a[i,j]= 4 then bon:=true
else if a[i,j]= 5 then nam:=true
else if a[i,j]= 6 then sau:=true
else if a[i,j]= 7 then bay:=true
else if a[i,j]= 8 then tam:=true
else if a[i,j]= 9 then chin:=true;
{So phan tu co trong mang}
for i:=1 to 10 do
if khong=true then begin b[i]:=0; khong:=false; k:=k+1; end
else if mot=true then begin b[i]:=1; mot:=false; k:=k+1 end
else if hai=true then begin b[i]:=2; hai:=false; k:=k+1 end
else if ba=true then begin b[i]:=3; ba:=false; k:=k+1 end
else if bon=true then begin b[i]:=4; bon:=false; k:=k+1 end
else if nam=true then begin b[i]:=5; nam:=false; k:=k+1 end
else if sau=true then begin b[i]:=6; sau:=false; k:=k+1 end
else if bay=true then begin b[i]:=7; bay:=false; k:=k+1 end
else if tam=true then begin b[i]:=8; tam:=false; k:=k+1 end
else if chin=true then begin b[i]:=9; chin:=false; k:=k+1 end;
write('Cac so 0-9 xuat hien trong bang:');
for i:=1 to k do
write(b[i],' ');
writeln;
{So lan xuat hien cua cac phan tu trong mang}
for l:=1 to k do
begin
m:=0;
for i:=1 to x do
for j:=1 to y do
if a[i,j]=b[l] then m:=m+1;
writeln('So lan xuat hien cua ',b[l],' la:',m);
end;
readln
END.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment