- 分享
- 0
- 人气
- 0
- 主题
- 5
- 帖子
- 1042
- UID
- 105681
- 积分
- 3194
- 阅读权限
- 21
- 注册时间
- 2007-10-19
- 最后登录
- 2012-8-4
- 在线时间
- 753 小时
|
- int[,] a = new int[20, 20];
- int i, j, n, p, sum1, sum2;
- string s = "left";
- Console.Write("输入方格大小:");
- n = int.Parse(Console.ReadLine());
- sum1 = 0;
- sum2 = n;
- p = 1;
- for (i = 1; i <= n; i++)
- for (j = 1; j <= n; j++)
- a[i, j] = 0;
- i = n; j = n; a[i, j] = p;
- while (p < n * n)
- {
- if (j == sum1)
- {
- j = 1; i--; s = "up";
- }
- if (i == sum1)
- {
- i = 1; j++; s = "right";
- }
- if (j == sum2 + 1)
- {
- j = n; i++; s = "down";
- }
- if (i == sum2)
- {
- sum2--; sum1++; i--; j--; s = "left";
- }
- if (s == "left")
- j--;
- if (s == "up")
- i--;
- if (s == "right")
- j++;
- if (s == "down")
- i++;
- p++;
- a[i, j] = p;
- }
- for (i = 1; i <= n; i++)
- {
- for (j = 1; j <= n; i++)
- Console.Write(a[i, j]);
- Console.WriteLine();
- }
复制代码
运行时输入后enter发生错误
有没有人highlight给我错误的地方?
em0009 |
|