C#的思路求解
											这个怎么写啊,求思路?高手帮帮忙!
[ 本帖最后由 宇智波曌 于 2011-10-19 13:44 编辑 ]
 2011-10-17 20:55
	    2011-10-17 20:55
   程序代码:
程序代码:Console.WriteLine("Input:");
            int n = int.Parse(Console.ReadLine());
            int[,] result = new int[n,n];
            int no = 1, direction = 0,x = 0,y=0;
            for (int i = 0; i < n * n; i++)
            {
                result[x, y] = no;
                if (direction == 0)
                {
                    if (y +1 == n || result[x,y+1]!=0)
                    {
                        direction = 1;
                        x++;
                    }
                    else
                        y++;
                }
                else if (direction == 1)
                {
                    if (x + 1 == n || result[x+1,y]!= 0)
                    {
                        direction = 2;
                        y--;
                    }
                    else
                        x++;
                }
                else if (direction == 2)
                {
                    if (y == 0 || result[x, y - 1] != 0)
                    {
                        direction = 3;
                        x--;
                    }
                    else
                        y--;
                }
                else if (direction == 3)
                {
                    if (result[x - 1, y] != 0)
                    {
                        direction = 0;
                        y++;
                    }
                    else
                        x--;
                }
                no++;
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Console.Write(result[i, j] + "\t");
                }
                Console.WriteLine();
            }
            Console.ReadLine();										
					
	 2011-10-18 11:13
	    2011-10-18 11:13
   2011-10-18 13:15
	    2011-10-18 13:15
   2011-10-18 22:28
	    2011-10-18 22:28
   2011-10-18 23:39
	    2011-10-18 23:39
  



 0
0										
					
	 2011-10-19 15:25
	    2011-10-19 15:25
   ,,,,,,,,,,
,,,,,,,,,,										
					
	 2011-10-28 21:23
	    2011-10-28 21:23