de thi hoc sinh gioi o tinh minh

H

hung1xpro96

Trả lời

Bạn xem thử bài giải này đúng không vậy ?
Mã:
Type mg=Record
  x,y:Integer;
End;
Var max,dem,i,j,n,m:Integer;
    a:array[1..100] Of Integer;
    b:array[1..100] Of mg;
    dd:array[1..100] Of Boolean;
    f,g:text;
Procedure nhap;
 Var i,j:Integer;
  Begin
   Writeln('nhap phan tu');
   Readln(n);
   For i:=1 to n do
    Begin
     Write('nhap phan tu thu ',i,' : ');
     Read(a[i]);
     Readln;
    End;
   Fillchar(dd,sizeof(dd),false);
  End;
Procedure ktra(t:Integer);
 Var i,j:Integer;
  Begin
   dd[t]:=true;
   inc(dem);
   b[dem].x:=t;
   b[dem].y:=1;
   For i:=1 to n do
    If dd[i]=false then
     If a[i]=a[t] then
      Begin
       inc(b[dem].y);
       dd[i]:=true;
      End;
  End;
Begin
 nhap;
 dem:=0;
 max:=0;
  For i:=1 to n do
   If dd[i]=false then ktra(i);
  For i:=1 to n do
   If b[i].y > max then max:=b[i].y;
  For i:=1 to n do
   If b[i].y=max then
    Begin
     Writeln(b[i].x);
     Writeln(b[i].y);
     break;
    End;
   Readln;
 End.
 
P

p_trk

Mã:
procedure init;
   begin 
        Fillchar(d,sizeof(d),true);
   end;
procedure xd;
  begin
        for i:=1 to n do 
           if d[i]:=true then 
             for j:=i to n do 
               if a[j]=a[i] then 
                      begin
                          d[j]:=false;  
                         dem:=dem+1; 
                          if dem>max then begin max:=dem; kq:=a[i] end;
                     end;
end;
 
Last edited by a moderator:
Top Bottom