编辑代码

using System;

public class HelloWorld
{
    public static void ShowMap(int [,] map)
    {
        int rows = map.GetLength(0);
        int cols = map.GetLength(1);

        if(rows<=0 || cols<=0) return;

        for(int r =0;r<rows;r++)
        {
            for(int c=0;c<cols;c++)
            {
                Console.Write($"{map[r,c]}");
            }
            Console.WriteLine("");
        }
    }
    public static int [,] Rotate(int [,] map)
    {
        int rows = map.GetLength(0);//4
        int cols = map.GetLength(1);//5
        //if(rows <= 0 || cols <= 0) return;

        int [,] newMap = new int[cols,rows];//5*4

        for(int x=0;x<cols;x++)//0..4
        {
            for(int y=0;y<rows;y++)//0..3
            {
                newMap[x, rows-y-1] = map[y,x];
            }
        }
        return newMap;
    }
    public static void Main()
    {
        int [,] map = new int[4,5] {
            {0,1,0,0,0},
            {0,1,0,0,0},
            {0,1,1,0,0},
            {0,1,1,1,0},
        };
       //JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。
        Console.WriteLine("HELLO world!     - cs.jsrun.net ");

        Console.WriteLine("Rotate 0:");
        ShowMap(map);

        int [,] newMap = Rotate(map);
        Console.WriteLine("Rotate 90:");
        ShowMap(newMap);

        int [,] newMap2 = Rotate(newMap);
        Console.WriteLine("Rotate 180:");
        ShowMap(newMap2);

        int [,] newMap3 = Rotate(newMap2);
        Console.WriteLine("Rotate 270:");
        ShowMap(newMap3);
    }
}