#include <iostream>
using namespace std;
int n;
int arr[101][101] = {0,};
int visited[101][101] = {0,};
void f(int x,int y,int s){
if (x > n || x < 1 || y > n || y < 1 ){
return;
}
if( arr[x][y] != 0 && arr[x][y] <= s) {
return;
}
arr[x][y] = s;
f(x,y+1,s+1);
f(x,y-1,s+1);
f(x+1,y,s+1);
f(x-1,y,s+1);
}
int main(){
int x,y;
int s = 1;
cin >> n;
cin >> x >> y;
f(x,y,s);
for (int i = 1;i <= n;i++){
for (int j = 1;j <= n;j++){
cout << arr[i][j] << " ";
}
cout << endl;
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: