fork download
  1. #include <iostream>
  2. using namespace std;
  3. /*
  4. Pasii de implementare:
  5. Declarăm “n” si coordonatele “x” si “y”.
  6. Citim “n” “x” si “y”.
  7. Declarăm și citim matricea.
  8. Pentru a afla indicii primului element al diagonalei cerute,
  9. cu ajutorul unei structuri repetitive, decrementam “x” și “y”
  10. pana cand unul dintre ei ajung la valoarea “1”.
  11.  
  12. Cu ajutorul unei structuri repetitive
  13. parcurgem diagonala cerută folosind noile valori a coordonatelor și o afisam.
  14. */
  15.  
  16. const int MAX_SIZE = 10;
  17.  
  18. int main() {
  19. int n, x, y, mt[MAX_SIZE + 1][MAX_SIZE + 1];
  20. cin >> n >> x >> y;
  21. for (int i = 1; i <= n; ++i) {
  22. for (int j = 1; j <= n; ++j) {
  23. cin >> mt[i][j];
  24. }
  25. }
  26. while (x >= 2 && y >= 2) {
  27. --x;
  28. --y;
  29. }
  30. for (int i = x, j = y; i <= n && j <= n; ++i, ++j) {
  31. cout << mt[i][j] << " ";
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5292KB
stdin



3 1 2
3 3 3
3 3 3
3 3 3 -> 3 3
stdout
3 3