Advertisement
alvsjo

Susjedne nule

Feb 27th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.73 KB | None | 0 0
  1. {
  2.     0 0 0 1 1 0 0 0 1 0 1 0
  3.     0 0 1 0 0 0 1 1 0 0 1 0
  4.     0 1 0 1 0 1 0 0 1 0 1 0
  5.     1 0 1 0 0 1 0 0 1 0 0 0
  6.     1 0 1 0 0 0 0 1 0 1 0 1
  7.     1 1 0 1 0 1 1 0 1 0 1 0
  8.  
  9.     susjedna polja nula
  10.     (ovdje ih ima 10)
  11.    
  12.     2 2 2 1 1 3 0 0 1 0 1 0
  13.     2 2 1 0 0 0 1 1 0 0 1 0
  14.     2 1 0 1 0 1 0 0 1 0 1 0
  15.     1 0 1 0 0 1 0 0 1 0 0 0
  16.     1 0 1 0 0 0 0 1 0 1 0 1
  17.     1 1 0 1 0 1 1 0 1 0 1 0
  18. }
  19.  
  20. program nule;
  21. type
  22.     niz=array[1..20]of integer;
  23.     matrica=array[1..20]of niz;
  24. var
  25.     br,m,n,i,j,rez,k,max,broj:integer;
  26. //  x,y,z:niz;
  27.     a,b,c:matrica;
  28.  
  29. procedure UnosMatrice(var m,n:integer; var a:matrica);
  30. var i,j:integer;
  31. begin
  32.     write('Broj vrsta: ');
  33.     readln(m);
  34.     write('Broj kolona: ');
  35.     readln(n);
  36.     for i:=1 to m do
  37.     begin
  38.         for j:=1 to n do
  39.         begin
  40.         write('A[',i,';',j,']= ');
  41.         readln(A[i,j]);
  42.         writeln;
  43.         end;
  44.     end;
  45. end;   
  46.  
  47.  
  48. procedure StampaMatrice(m,n:integer; A:matrica);
  49. var i,j:integer;
  50. begin
  51.     writeln;
  52.     for i:=1 to m do
  53.     begin
  54.         for j:=1 to n do
  55.         begin
  56.         write(A[i,j]:4);
  57.         end;
  58.         writeln;
  59.     end;
  60.     writeln;
  61. end;
  62.  
  63. procedure popunjavanje(m,n,i,j,broj:integer; var a:matrica);
  64. begin
  65.     a[i,j]:=broj;
  66.     br:=br+1;
  67.     if (j<n) then if a[i,j+1]=0 then popunjavanje(m,n,i,j+1,broj,a);
  68.     if (i<m) then if a[i+1,j]=0 then popunjavanje(m,n,i+1,j,broj,a);
  69.     if (j>1) then if a[i,j-1]=0 then popunjavanje(m,n,i,j-1,broj,a);
  70.     if (i>1) then if a[i-1,j]=0 then popunjavanje(m,n,i-1,j,broj,a);
  71. end;
  72.  
  73.  
  74. begin
  75. UnosMatrice(m,n,a);
  76. StampaMatrice(m,n,a);
  77. broj:=1; max:=0;
  78. for i:=1 to m do
  79.     for j:=1 to n do
  80.     begin
  81.     if a[i,j]=0 then
  82.         begin
  83.         br:=0;
  84.         broj:=broj+1;
  85.         popunjavanje(m,n,i,j,broj,a);
  86.         if (br>max) then
  87.             begin
  88.             max:=br;
  89.             rez:=broj;
  90.             end;
  91.         end;
  92.     end;
  93. StampaMatrice(m,n,a);
  94. writeln;
  95. writeln(max:8,rez:8);
  96. readln;
  97. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement