Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- namespace CSharp_Shell
- {
- public enum Rotation {right, left};
- public class Matrix
- {
- private int[,] arr;
- private int length;
- public int this[int index1, int index2]
- {
- set{
- arr[index1, index2] = value;
- }
- get{
- return arr[index1, index2];
- }
- }
- public Matrix(int length)
- {
- arr = new int[length, length];
- this.length = length;
- }
- public void Print()
- {
- for(int a = 0; a < length; a++)
- {
- for(int b = 0; b < length; b++)
- Console.Write(arr[a,b]);
- Console.WriteLine("");
- }
- }
- public void RandomFill()
- {
- Random rand = new Random();
- for(int i = 0; i < arr.Length; i++)
- {
- arr[i/length, i%length] = rand.Next(9);
- }
- }
- public void Rotate(Rotation rot=Rotation.right, int times=1)
- {
- for(int t = 0; t < times; t++)
- {
- int[,] result = new int[length, length];
- for (int i = 0; i < length; i++)
- for (int j = 0; j < length; j++)
- result[i, j] = (rot == Rotation.right)?(arr[length - j - 1, i]):(arr[j, length - i - 1]);
- arr = result;
- }
- }
- }
- public static class Program
- {
- public static void Main()
- {
- int num = Console.ReadLine<Int32>();
- Matrix matrix = new Matrix(num);
- string s;
- do
- {
- s = Console.ReadLine();
- switch(s)
- {
- case "right":
- case "left":
- matrix.Rotate((s == "right")?Rotation.right:Rotation.left, Console.ReadLine<Int32>());
- break;
- case "print":
- matrix.Print();
- break;
- case "random":
- matrix.RandomFill();
- break;
- }
- } while(s != "exit");
- matrix.RandomFill();
- matrix.Print();
- Console.WriteLine("-------");
- matrix.Rotate();
- matrix.Print();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement