Advertisement
Sli4

Rotate a Matrix

Jun 9th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _9.Rotate_a_Matrix
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int rows = int.Parse(Console.ReadLine());
  14.             int cow = int.Parse(Console.ReadLine());
  15.  
  16.             string[,] matrix = new string[rows, cow];
  17.  
  18.             for (int i = 0; i < rows; i++)
  19.             {
  20.                 string inputRow = Console.ReadLine(); // чете целия ред
  21.                 string[] inputCols = inputRow.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); // прави ми ги на масив, като премахва интервалите
  22.  
  23.                 for (int k = 0; k < cow; k++)
  24.                 {
  25.                     matrix[i, k] = inputCols[k]; // присвоява k
  26.                 }
  27.                 Console.WriteLine();
  28.             }
  29.  
  30.             for (int i = 0; i < cow; i++)
  31.             {
  32.                 for (int k = 0; k < rows; k++)
  33.                 {
  34.                     Console.Write(matrix[rows - 1 - k, i] + " ");
  35.                 }
  36.                 Console.WriteLine();
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement