fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. /*
  4. Ideea generala de rezolvare:
  5. Dupa ce calculam ambele tipuri de distante, le comparam si
  6. afisam mesajul cerut.
  7.  
  8.  
  9. Pasii de rezolvare:
  10. Declaram si citim datele de intrare.
  11. Declaram variabilele "manSum" si "compSum" pe care le initializam cu valoarea "0"
  12.  
  13. Facem suma dintre distanta liniilor si distanta coloanelor, pe care o salvam in "manSum".
  14.  
  15. - Parcurgem prima linie a matricei, pana la coordonata coloanei data de variabila "y",
  16. facand suma valorilor elementelor pe care o salvam in "manSum".
  17. - Parcurgem coloana matricei data de coordonata "y"
  18. incepand de la linia "1" pana la linia "x",
  19. si facem suma valorilor elementelor pe care o salvam in "manSum".
  20. Comparam cele doua variabile si afisam ce se cere.
  21. Teste:
  22. 3 2 2
  23. 0 1 2
  24. 3 4 5
  25. 1 2 3
  26. -> Computing way
  27.  
  28. 4 3 3
  29. 1 2 3 4
  30. 5 6 7 8
  31. 9 10 11 12
  32. 13 14 15 16
  33. -> Manhattan way
  34. */
  35.  
  36. const int MAX_SIZE = 5;
  37.  
  38. int main() {
  39. int n, x, y;
  40. cin >> n >> x >> y;
  41. int mt[MAX_SIZE + 1][MAX_SIZE +1] = {0};
  42. for (int i = 1; i <= n; ++i) {
  43. for (int j = 1; j <= n; ++j) {
  44. cin >> mt[i][j];
  45. }
  46. }
  47. int manSum = (x - 1) + (y - 1);
  48. int compSum = 0;
  49. for (int i = 1; i < y; ++i) {
  50. compSum += mt[1][i];
  51. }
  52. for (int i = 1; i < x; ++i) {
  53. compSum += mt[i][y];
  54. }
  55. if (manSum < compSum) {
  56. cout << "Manhattan way";
  57. } else if (compSum < manSum) {
  58. cout << "Computing way";
  59. } else {
  60. cout << "Both ways";
  61. }
  62. return 0;
  63. }
Success #stdin #stdout 0s 5284KB
stdin
1 1 1
0


3 2 2
0 1 2
3 4 5
1 2 3

4 3 3
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
stdout
Both ways