Skip to content

Instantly share code, notes, and snippets.

@EBojilova
Created May 9, 2015 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EBojilova/fc4cc3b81b6698ec9f4f to your computer and use it in GitHub Desktop.
Save EBojilova/fc4cc3b81b6698ec9f4f to your computer and use it in GitHub Desktop.
11. String Matrix Rotation
using System;
using System.Collections.Generic;
using System.Linq;
class StringMatrixRotation
{
static void Main(string[] args)
{
string[] rotation = (Console.ReadLine().Split(new char[] { '(', ')', ' ' },
StringSplitOptions.RemoveEmptyEntries));
int degrees = (int.Parse((rotation[1]))) % 360;
var words = new List<string>();
string input;
while (!((input = Console.ReadLine()) == "END"))
{
words.Add(input);
}
int height = words.Count();
int width = words.OrderBy(x => x.Length).Last().Length;
string[] matrix=new string[height];
for (int row = 0; row < height; row++)
{
matrix[row] = words[row].PadRight(width, ' ');
}
if (degrees==0)
{
for (int row = 0; row < height; row++)
{
Console.WriteLine(matrix[row]);
}
}
if (degrees==180)
{
for (int row = height-1; row >=0; row--)
{
for (int col = width-1; col>=0; col--)
{
Console.Write(matrix[row][col]);
}
Console.WriteLine();
}
}
if (degrees == 90)
{
for (int col = 0; col < width; col++)
{
for (int row = height-1; row >= 0; row--)
{
Console.Write(matrix[row][col]);
}
Console.WriteLine();
}
}
if (degrees == 270)
{
for (int col = width-1; col >=0; col--)
{
for (int row = 0; row <height; row++)
{
Console.Write(matrix[row][col]);
}
Console.WriteLine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment