#include<iostream>
#define MAX 110
#define REPi(i,m) for (int i=1; i<=(m); i++)
#define REPj(j,n) for (int j=1; j<=(n); j++)
using namespace std;
void init();
void readInput();
void slover();
void PrintWriter();
void Loang(int, int);
int m, n, result;
int a[MAX][MAX], d[MAX][MAX]; // array a is main array; array d is trace array
main()
{
init(); //initialize
readInput();
slover();
PrintWriter();
}
//init
void init()
{
for (int i=0; i<=MAX+1; i++)
for (int j=0; j<=MAX+1; j++)
{
a[i][j] = 0;
d[i][j] = 0;
}
}
//
void readInput()
{
cin>> m >> n ;
REPi(i,m) REPj(j,n) cin>>a[i][j];
}
//
void loang(int x, int y)
{
int X, Y;
int d1[] = {1,-1,0,0};
int d2[] = {0,0,1,-1};
d[x][y] = 1;
for (int i=0; i<=3; i++)
{
X = x + d1[i];
Y = y + d2[i];
if ((a[X][Y] == 1)&&(d[X][Y] == 0)){
loang(X,Y);
}
}
}
//
void slover()
{
result = 0;
REPi(i,m) REPj(j,n)
{
if ((a[i][j] == 1)&&(d[i][j] == 0)){
loang(i,j);
result++;
}
else continue;
}
}
//
void PrintWriter()
{
cout<<result;
}
Mình có đoạn code này, nhưng không hiểu bạn viết code này để tính caí gì. Mong mọi người chỉ dùm, cảm ơn! 
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?