111,125
社区成员
发帖
与我相关
我的任务
分享
static void Main(string[] args)
{
char[][] arry = new char[][] { new char[]{'a','b','c','d','e','f'},
new char[]{'g','h','i','j','k','l'},
new char[]{'m','n','o','p','q','r'},
new char[]{'s','t','u','v','w','x'} };
Print(arry, 0, 0, true);
Console.ReadLine();
}
private static void Print(char[][] arry, int row, int col, bool bIsCol)
{
if (bIsCol)
{
for (int i = row; i < arry.Length; i++)
Console.Write(arry[i][col]);
Console.WriteLine("");
if (col + 1 < arry[0].Length && row < arry.Length)
Print(arry, row, col + 1, !bIsCol);
}
else
{
for (int i = col; i < arry[row].Length; i++)
Console.Write(arry[row][i]);
Console.WriteLine("");
if (row + 1 < arry.Length && col < arry[0].Length)
Print(arry, row + 1, col, !bIsCol);
}
}
输出结果:
agms
bcde
hnt
ijkl
ou
pqr
v
wx
