Advertisement
Guest User

Xuất ra mảng 2 chiều bị xoay theo chiều kim đồng hồ 90 độ

a guest
Feb 25th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.40 KB | None | 0 0
  1. int[,] two_dimension_array = new int[3,3] {
  2.     { 1,2,3 },
  3.     { 4,5,6},
  4.     { 7,8,9 }
  5. };
  6.  
  7. int[,] rotated = RotateMatrix(two_dimension_array, 4);
  8.  
  9. static int[,] RotateMatrix(int[,] matrix, int n) {
  10.     int[,] ret = new int[n, n];
  11.  
  12.     for (int i = 0; i < n; ++i) {
  13.         for (int j = 0; j < n; ++j) {
  14.             ret[i, j] = matrix[n - j - 1, i];
  15.         }
  16.     }
  17.  
  18.     return ret;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement