fork download
  1. #include <iostream>
  2. using namespace std;
  3. /*
  4. Pasii de implementare:
  5. Declaram și citim următoarele variabile: “n”, “x”, “y”.
  6. Declarăm și initializam cu zero: matricea de marime maxima și
  7. variabila “highestVal” în care se stochează valoarea maximă găsită.
  8.  
  9. În timpul citirii elementelor matricei:
  10. Dacă valoarea elementului curent este mai mare decat
  11. valoarea variabilei “highestVal”,
  12. aceasta preia valoarea elementului curent.
  13.  
  14. Parcugand elementele matricei:
  15. Dacă elementul curent este egal cu variabila “highestVal” și
  16. “highestVal” este diferit de elementul de coordonate “x” “y”, atunci, elementul curent preia valoarea elementului de coordonate “x” “y”.
  17. Afisam elementul curent.
  18. */
  19.  
  20. const int MAX_VALUE = 10;
  21.  
  22. int main() {
  23. int n, x, y;
  24. cin >> n >> x >> y;
  25. int mt[MAX_VALUE + 1][MAX_VALUE + 1], highestVal = 0;
  26. for (int i = 1; i <= n; ++i) {
  27. for (int j = 1; j <= n; ++j) {
  28. cin >> mt[i][j];
  29. if (mt[i][j] > highestVal) {
  30. highestVal = mt[i][j];
  31. }
  32. }
  33. }
  34. for (int i = 1; i <= n; ++i) {
  35. for (int j = 1; j <= n; ++j) {
  36. if (mt[i][j] == highestVal && highestVal != mt[x][y]) {
  37. mt[i][j] = mt[x][y];
  38. }
  39. cout << mt[i][j] << " ";
  40. }
  41. cout << "\n";
  42. }
  43. return 0;
  44. }
  45. /*
  46. 1 2 3 4 3
  47. 3 2 3 4 3
  48. 1 3 3 4 3
  49. 1 2 3 4 3
  50. 3 2 3 4 1
  51. */
Success #stdin #stdout 0.01s 5280KB
stdin
5 3 3
1 2 3 4 5
5 2 3 4 5
1 5 3 4 5
1 2 3 4 5
5 2 3 4 1 –
1 2 3 4 3
3 2 3 4 3
1 3 3 4 3
1 2 3 4 3
3 2 3 4 1

stdout
1 2 3 4 3 
3 2 3 4 3 
1 3 3 4 3 
1 2 3 4 3 
3 2 3 4 1