Created
June 21, 2013 22:19
-
-
Save ichensky/5834767 to your computer and use it in GitHub Desktop.
rotate matrix on angel 90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication2 | |
{ | |
class Program | |
{ | |
// Input: | |
// 1 2 3 | |
// 4 5 6 | |
// 7 8 9 | |
// Output: | |
// 7 4 1 | |
// 8 5 2 | |
// 9 6 3 | |
static void Rotete90(string[,] mas, int count) | |
{ | |
var x = count - 1; | |
for (var i = 0; i < count; i++) | |
{ | |
for (var j = 0; j < count; j++) | |
{ | |
var a = mas[j, x - i]; | |
mas[j, x - i] = mas[i, j]; | |
mas[i, j] = a; | |
} | |
} | |
} | |
static void cw(string[,] mas, int count) | |
{ | |
for (var i = 0; i < count; i++) | |
{ | |
for (var j = 0; j < count; j++) | |
{ | |
Console.Write(mas[i, j] + " "); | |
} | |
Console.WriteLine(""); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
var mas = new string[5, 5]; | |
for (var i = 0; i < 5; i++) | |
{ | |
for (var j = 0; j < 5; j++) | |
{ | |
mas[i, j] = "i" + i + " j" + j; | |
} | |
} | |
cw(mas, 5); | |
Console.WriteLine(); | |
Rotete90(mas, 5); | |
cw(mas, 5); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment