using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Myjuzheng
{
class Program
{
static int[,] shuzu;
static void Main(string[] args)
{
shuzu = new int[20, 20];
int i=0;
int j=0;
shuzu[0, 0] = 1;
for (int num = 2; num <=shuzu.Length ; num++)
{
if (panduan(i, j + 1) && !panduan(i - 1, j))
{
shuzu[i, j + 1] = num;
j++;
continue;
}
if (panduan(i + 1, j) && !panduan(i, j + 1))
{
shuzu[i + 1, j] = num;
i++;
continue;
}
if (panduan(i, j - 1) && !panduan(i + 1, j))
{
shuzu[i, j-1] = num;
j--;
continue;
}
if (panduan(i - 1, j) && !panduan(i, j - 1))
{
shuzu[i - 1, j] = num;
i--;
continue;
}
}
for (int m= 0; m < shuzu.GetLength(0); m++)
{
for (int n = 0; n <shuzu.GetLength(0); n++)
{
Console.Write("{0,4}", shuzu[m, n]);
}
Console.WriteLine();
}
Console.Read();
}
static bool panduan(int x, int y)
{
if (x < 0 || x >= shuzu.GetLength(0) || y < 0 || y >= shuzu.GetLength(0))
return false;
if (shuzu[x, y] != 0)
return false;
return true;
}
}
}