回字形

int cnt = 1;
f0r(i, n / 2)
{
	REP(j, i, n - i)a[j][n - i - 1] = cnt++;
    neREP(j, n - i - 2, i) a[n - i - 1][j] = cnt++;
    neREP(j, n - i - 2, i) a[j][i] = cnt++;
    REP(j, i + 1, n - i - 1) a[i][j] = cnt++;
}
 
if (n & 1)
{
	a[n / 2][n / 2] = a[n / 2 - 1][n / 2] + 1;
}
f0r(i, n)
{
	f0r(j, n)
	{
		cout << a[i][j] << " ";
	}
	cout << "\n";
}

三角形