fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 50;
  5.  
  6. int main() {
  7. int mtSize, windLine[MAX_SIZE + 1][MAX_SIZE + 1];
  8. cin >> mtSize;
  9. for (int line = 1; line <= mtSize; ++line) {
  10. for (int col = 1; col <= mtSize; ++col) {
  11. cin >> windLine[line][col];
  12. }
  13. }
  14. //int lineDir = 0, colDir = 1;
  15. /*
  16. cosmin
  17. 2025-02-23 11:19:54
  18. combine these 2 variables into a single direction variable -> solved
  19. */
  20. for (int linePos = 1, colPos = 1; linePos <= mtSize && colPos <= mtSize; ) {
  21. /*
  22. cosmin
  23. 2025-02-23 11:23:47
  24. there should be an empty space after the ";" -> solved
  25. */
  26. cout << windLine[linePos][colPos] << " " << endl;
  27. if (linePos == 1 && colPos == 1) {
  28. ++colPos;
  29. }
  30. //int lPlusC = linePos + colPos;
  31. /*
  32. cosmin
  33. 2025-02-23 11:24:30
  34. get rid of this variable -> solved
  35. */
  36. if ((linePos + colPos) % 2 && ((linePos == 1 && colPos <= mtSize &&
  37. colPos >= 1) || (colPos == mtSize && linePos >= 1 &&
  38. linePos <= mtSize))) {
  39. /*
  40. cosmin
  41. 2025-02-23 11:24:36
  42. simplify these conditions
  43. */
  44. // if1
  45. linePos += 1;
  46. colPos += -1;
  47. cout << "if1" << linePos << " " << colPos << endl;
  48. }
  49. if ((linePos + colPos) % 2 == 0 && ((colPos == mtSize && linePos >= 1 &&
  50. linePos <= mtSize) || (linePos == 1 && colPos <= mtSize &&
  51. colPos >= 1))) {
  52. linePos += -1;
  53. //if2
  54. colPos += 1;
  55. cout << "if2" << linePos << " " << colPos << endl;
  56. }
  57. if ((colPos == 1 && linePos < mtSize && linePos > 1) ||
  58. (colPos == mtSize && linePos >= 1 && linePos <= mtSize)) {
  59. //if3
  60. linePos += 1;
  61. colPos += 0;
  62. cout << "if3" << linePos << " " << colPos << endl;
  63. }
  64. if ((linePos == mtSize && colPos >= 1 && colPos <= mtSize) ||
  65. (linePos == 1 && colPos < mtSize && colPos >= 1)) {
  66.  
  67. //if4
  68. linePos += 0;
  69. colPos += 1;
  70. cout << "if4" << linePos << " " << colPos << endl;
  71. }
  72. //linePos += lineDir;
  73. //colPos += colDir;
  74. //lPlusC = linePos + colPos;
  75. cout << "endfor" << endl;
  76. }
  77. return 0;
  78. }
Success #stdin #stdout 0.01s 5296KB
stdin
5
11 12 13 14 15
21 22 23 24 25
31 32 33 34 35
41 42 43 44 45
51 52 53 54 55
stdout
11 
if12 1
if33 1
endfor
31 
if34 1
endfor
41 
if35 1
if45 2
endfor
52 
if45 3
endfor
53 
if45 4
endfor
54 
if45 5
endfor
55 
if24 6
endfor