fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 50;
  5.  
  6. int main() {
  7. int line, col, mt[MAX_SIZE][MAX_SIZE]; // Indexare de la 0
  8. cin >> line >> col;
  9.  
  10. // Citirea matricei
  11. for (int m = 0; m < line; ++m) {
  12. for (int n = 0; n < col; ++n) {
  13. cin >> mt[m][n];
  14. }
  15. }
  16.  
  17. int i, j, l;
  18. cin >> i >> j >> l;
  19.  
  20. // Verificăm dacă submatricea este pătratică
  21. if (l - i != l - j) {
  22. cout << "Submatricea trebuie să fie pătratică!" << endl;
  23. return 1;
  24. }
  25.  
  26. // Rotește submatricea cu 90 de grade spre stânga
  27. for (int m = 0; m < l - i + 1; ++m) {
  28. for (int n = 0; n < l - j + 1; ++n) {
  29. // Copiem elementele în noua poziție
  30. // Elementul (m, n) va merge la (l - j - n + i, m + j - i)
  31. mt[l - j - n][m + j] = mt[i + m][j + n];
  32. }
  33. }
  34.  
  35. // Afișăm matricea rezultată
  36. for (int m = 0; m < line; ++m) {
  37. for (int n = 0; n < col; ++n) {
  38. cout << mt[m][n] << " ";
  39. }
  40. cout << "\n";
  41. }
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 5288KB
stdin
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
2 2 2
stdout
1 2 11 4 
5 6 7 8 
9 10 11 12 
13 14 15 16